Not having my first "FOR LOOP" numbers assigned inside my MATLAB code
1 回表示 (過去 30 日間)
古いコメントを表示
Mohammad Dabbagh
2021 年 4 月 25 日
コメント済み: Mohammad Dabbagh
2021 年 4 月 25 日
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!