how to loop through variables names?
60 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bas Dirriwachter
am 28 Okt. 2020
Beantwortet: Bas Dirriwachter
am 29 Okt. 2020
I have an export from a FEA program (.dat file). I was able to convert them into a specifc array i need. Since they are imported they all have their own name so this is layer1, layer2 etc. I want to compare them so want to plot hem together. since these are over a 100 layers (and this has to be repeated over 16 times) i was hoping to create a loop in the variable name. i found a way to create a string with the corresponding variable names using the following code
(for trying i use just 5 layers)
n=5
L=string(zeros(n,1))
for i = 1:n
L(i)=string(sprintf('layer%d',i))
end
but since it is a string you cannot put this iside the plot command. therefore I tried to connect the name to the variable using the eval command
i know every matlab page recommendes to not use this command
z= eval(L(1))
When I recall z for L(1) it will give the array for L(1) and when I call for L(2) z will give me the correct array but i cannot loop this. Also a loop to combine them in one matrix failed.
When I googled a bit more i came accress cell arrays but I still cannot find a whay to succeed.
If I can loop through the variable names I can do both plotting all arrays and combine them into one matrix (which is also need).
3 Kommentare
Stephen23
am 28 Okt. 2020
"Since they are imported they all have their own name so this is layer1, layer2 etc."
This importing is cause of your difficulties. This is the step that you should fix. But so far you have not given us any information on exactly how you imported the data: what function/s, with what code?
If you tell us a bit about the file importing, someone can help you to improve it (and avoid the bad code).
Bas Dirriwachter
am 29 Okt. 2020
Bearbeitet: Bas Dirriwachter
am 29 Okt. 2020
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements 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!