how to loop through variables names?
58 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Bas Dirriwachter
el 28 de Oct. de 2020
Respondida: Bas Dirriwachter
el 29 de Oct. de 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 comentarios
Stephen23
el 28 de Oct. de 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
el 29 de Oct. de 2020
Editada: Bas Dirriwachter
el 29 de Oct. de 2020
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!