Not having my first "FOR LOOP" numbers assigned inside my MATLAB code
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi all,
I was wondering if anyone could assist me with a silly question on MATLAB! The story is that I'm generating some numbers in my code, catgorized into two separate ranges. Now, I need to implement those numbers in the other part of my code, as follows:
xs = strings(1,24);
for i= 1:24
if x(i)==1
xs(i) = "Set WinS_Construct = R1WinConstruction";
elseif x(i)==2
xs(i) = "Set WinS_Construct = R2WinConstruction";
elseif x(i)==3
xs(i) = "Set WinS_Construct = R3WinConstruction";
elseif x(i)==4
xs(i) = "Set WinS_Construct = R4WinConstruction";
end
end
xs = strings(25,29);
for i= 25:29
if x(i)==13
xs(i) = "13";
elseif x(i)==14
xs(i) = "14";
elseif x(i)==15
xs(i) = "15";
elseif x(i)==16
xs(i) = "16";
elseif x(i)==17
xs(i) = "17";
elseif x(i)==18
xs(i) = "18";
end
end
While I could sucessfully generate the "x" numbers, I'm not sure why MATLAB does not generate any number for my first loop. To calrify more, my "xs" strings includes only numbers for i=25:29- and I'm missing "xs" strings for i=1:24!
Any help would be greatly appreciated!
Thanks!
채택된 답변
Walter Roberson
2021년 4월 25일
xs = strings(25,29);
That line of code requests that all of xs be overwritten with a 25 by 29 array of string objects.
Remove that line and change
xs = strings(1,24);
to
xs = strings(1,29);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!