Not having my first "FOR LOOP" numbers assigned inside my MATLAB code
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Mohammad Dabbagh
il 25 Apr 2021
Commentato: Mohammad Dabbagh
il 25 Apr 2021
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!
1 Commento
Risposta accettata
Walter Roberson
il 25 Apr 2021
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);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!