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!