How to add array of data into a variable?says i wanna loop for 4times

1 view (last 30 days)
N=4;
for i=1:N
myArray(i) = [i+1 i+2];
end

Accepted Answer

Star Strider
Star Strider on 14 Apr 2018
You need to add a second dimension to ‘myArray’ to so what you want:
N=4;
for i=1:N
myArray(i,:) = [i+1 i+2];
end
  7 Comments
Walter Roberson
Walter Roberson on 15 Apr 2018
The C equivalent would be
for( i=1; i<=20; i+=2 )
The MATLAB is just rearranging that with a minor syntax difference.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!