Accessing data in doubles with incremental names using a loop
Mostrar comentarios más antiguos
I have a list of data (doubles containing temperature and time stamp readings) with files names in an incresing order and I need to access temperature measurements from them.
Ex: I have the following doubles: Meas_Temp_1, Meas_Temp_2 and so on until Meas_Temp_60
I need a loop which will get me all the temperature readings in different variables, say
Temp n = Meas_Temp_n (:,1) -----> store the temperature data in the first column into variables
I am unable to extract the readings while I am able to access the doubles.
3 comentarios
Bob Thompson
el 14 de Mzo. de 2019
Just to clarify, you have MATLAB workspace variable which are classed as doubles that have progressive names? If so, where do these variables come from?
It is generally considered bad practice to create a series of variables like this, and our first recommendation will be to change the creation method for these variables to create a multidimensional matrix.
Sachin Shridhar Paradkar
el 14 de Mzo. de 2019
"I have the following doubles: Meas_Temp_1, Meas_Temp_2 and so on until Meas_Temp_60"
Then you really really need to fix your data design. Numbered variables are a sign that you are doing something wrong.
"the creation of these variables in any other format is not possible given that it is from BMS. "
Saying that the data is "from BMS" tells us nothing about its format (e.g. is the data stored in files (what file format?) or as variables magically created in the workspace by a very badly written tool?).
In any case you should fix your code where the data is imported or created. For example, rather than load-ing into separate variables, simply load into one output variable (which is a structure):
S = load(...);
"I am unable to extract the readings while I am able to access the doubles."
Dynamically accessing variable names is one way that beginners force themselves into writing slow, complex, obfuscated, buggy code that is hard to debug. Read this to know some of the reasons why:
Respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!