use "for loop" to create pattern
3 views (last 30 days)
Show older comments
I would like to know how to modify my "second for loop" to obtain the "a" result as below picture.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/802354/image.png)
Thank you very much!
clc
clear
plynumber=3;
stackply=3;
plysym=1;
total=plynumber*stackply*plysym;
for i=1:plynumber % first for loop
a(1,i)=input('a=')
end
for i=1+plynumber:total % second for loop
2 Comments
Image Analyst
on 16 Nov 2021
OK, so that is your desired final a, but is supposed to depend on your a from loop 1 at all? Or you just want that a regardless of what a was from the first loop? Because I think to get your desired a, it's basically going to totally ignore the a from your first loop.
Accepted Answer
David Hill
on 16 Nov 2021
Why not just use repmat() instead of a for-loop?
a=repmat(a,1,3);
5 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!