I would like to know how to modify my "second for loop" to obtain the "a" result as below picture.
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

Image Analyst
Image Analyst 2021년 11월 16일
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.
Mark
Mark 2021년 11월 16일
Yes, I would like to depend on my loop 1 because I need to analyze my plynumber first in my program. I would like to create a input for my program so that's why I create the first for loop to store my input. The purpose is to make the every input I enter can follow the pattern as the picture I posted.

댓글을 달려면 로그인하십시오.

 채택된 답변

David Hill
David Hill 2021년 11월 16일

1 개 추천

Why not just use repmat() instead of a for-loop?
a=repmat(a,1,3);

댓글 수: 5

Mark
Mark 2021년 11월 16일
Thanks David! repmat is more easier to use! How about creating a symmetric pattern as below picture. Could I also use repmat founction?
a=[45 -45 0 0 -45 45];
a=[repmat(a(1:3),1,2),repmat(a(4:6),1,2)];
Mark
Mark 2021년 11월 16일
Could you generate a=[45 -45 0 0 -45 45] by using repmat as well? Or is there any other way to generate this pattern? Thanks!
a=[45 -45 0];
a=[a,flip(a)];
Mark
Mark 2021년 11월 16일
Got it! Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2021a

태그

질문:

2021년 11월 16일

댓글:

2021년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by