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!