Accessing data in doubles with incremental names using a loop
显示 更早的评论
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 个评论
Bob Thompson
2019-3-14
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
2019-3-14
"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:
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!