How to add strings to a list
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How do I add strings to a list. I used if staements and used the functions append but its not working if one if statement is wrong. I dont know if I need to use a loop.
diagnosistitle = [];
x = 1;
y = 1;
z = 1;
if x == 1
str1 = append("X");
end
if y == 1
str2 = append("Y");
end
if z == 2
str3 = append("Z");
end
str = append(str1, str2, str3);
2 Kommentare
the cyclist
am 2 Okt. 2019
It's probably important to distinguish between strings and character arrays here.
Antworten (1)
the cyclist
am 2 Okt. 2019
So, I'm not sure what are really trying to do. But the problem with your specific code is that because this if structure is not entered
if z == 2
str3 = append("Z");
end
then the variable str3 simply does not exist, when is why the line
str = append(str1, str2, str3);
fails.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!