Call on Dynamic Variable
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have data ingest for sensors 1 through n which I identify as sensor1 through sensorn. I am wanting to write a for loop to control which data array I am calling.
Here is an example of what I am trying to accomplish:
for g=1:19
nanRows=any(isnan(sensor(g)),2);
sensor(g)(nanRows, :) = [];
Esensor(g)=average-sensor(g);
SEsensor(g)=Esensor(g).^2;
ssensor(g)=sensor(g);
g=g+1;
end
I am realizing that (g) does not provide a variable accordingly. Any suggestions?
Thanks!
Janae
0 commentaires
Réponses (2)
James Tursa
le 16 Mar 2015
Please see this post about having variables named sensor1, sensor2, sensor3, etc and then trying to process them in a loop:
Bottom line is that it can be done using the eval function, but it is very messy as you are finding out. It would be much better to restructure your data into cell or struct arrays. They will be much easier to process in loops, and there will be a variety of supplied functions in MATLAB to deal with data stored this way.
0 commentaires
Adam
le 16 Mar 2015
Similar question, similar answer:
If you can't use a normal double array then use a cell array or a struct with dynamic fields as a 2ndd choice.
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!