How to add array of data into a variable?says i wanna loop for 4times
1 view (last 30 days)
Show older comments
Fatefly Yip
on 14 Apr 2018
Commented: Star Strider
on 15 Apr 2018
N=4;
for i=1:N
myArray(i) = [i+1 i+2];
end
0 Comments
Accepted Answer
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
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.
More Answers (0)
See Also
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!