LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Start FOR loop from specified iteration number

Solved!
Go to solution

Hi,

I want to start a Foor loop from 2 and end it to 5. Meaning that any process inside the foor loop must start from second loop and end till 5th loop. This is how my question would like in Matlab.


for i=2:5

 

Help is appreciated. 


0 Kudos
Message 1 of 14
(7,094 Views)

Wire a 4 to N and add two to the value coming from the iteration terminal.

0 Kudos
Message 2 of 14
(7,091 Views)

This is what I'm trying to do

 

p=zeros(4,4);
for i=2:4
for j=2:4
p(i,j)=i+j
end
end

 

 

result should be

 


p =

0 0 0 0
0 4 5 6
0 5 6 7
0 6 7 8

 

 


0 Kudos
Message 3 of 14
(7,085 Views)
You can not define the intial value of the iteration terminal in LabVIEW. The only legit solution is what is suggested earlier: wire 4 to the N terminal, and add 2 to the value of the I terminal. The result will be what you asked for.

Hope this helps.
0 Kudos
Message 4 of 14
(7,079 Views)

Did what you told, getting correct values but how would I get the result in a matrix form as 

 

p =

0 0 0 0
0 4 5 0
0 5 6 0
0 0 0 0

 

I've attached a screenshot of what I did and what I'm geting.

 

 


0 Kudos
Message 5 of 14
(7,069 Views)

You did not follow the instructions you were given. Wire 4 to the N terminals.

 

Lynn

0 Kudos
Message 6 of 14
(7,060 Views)
Originally you have asked for a different matrix. I suggest (as earlier) to try N=4 and not 2
0 Kudos
Message 7 of 14
(7,056 Views)

Wired!

This is what I'm getting now Untitled.png


0 Kudos
Message 8 of 14
(7,055 Views)
Solution
Accepted by NapDynamite

@NapDynamite wrote:

This is what I'm trying to do

 

p=zeros(4,4);
for i=2:4
for j=2:4
p(i,j)=i+j
end
end

 

 

result should be

 


p =

0 0 0 0
0 4 5 6
0 5 6 7
0 6 7 8

 

 


You should be aware that in LabVIEW the first element has index 0, while e.g. in matlab the first element has index 1

 

To get the above result, here's what you could do. (your elements are symmetric. If they are not, you might need to swap the index inputs, depending on what you actually want)

 

Here's what you could do... (initialize array replaces the "zeroes" function.

 

 

Message 9 of 14
(7,018 Views)

Have you used Replace array or Insert Into Array inside the second loop?

Can you please send me this VI? 😞


0 Kudos
Message 10 of 14
(6,997 Views)