Access to struct atrribute for changing names
Show older comments
Hello dear MATLAB forum,
I am working with MATLAB and Simulink as part of my bachelor thesis. The situation is as follows:
I have to calculate a temperature from different test data sets. The test data are each stored in a structure, which is drawn for a machine e.g. as "newMPsOfRun6010_03". Now I have many other test data sets like newMPsOfRun6011_03, newMPsOfRun6012_02 and so on.
I would like to do the calculation for all records in one run. So far I've done this by copying the code for one record and only changing the name of the record. However, this is not so nice and would degenerate with several records.
So I ask you for help on how to do this in a loop. In this way this should be done for example:
MPs = [8;8;8;38]; % Number of measuring points in the data set
runs = {'6010_03', '6011_03', '6012_02', '6014_01'}; % Record name ending
for i = 1 : length(runs)
run = strcat('newMPsOfRun', runs{i});
for j = 1:MPs(i)
T5 = run.Performance.T5.MPVector(j); % Access to Record
end
end
My problem with this is that I can not use the '.' operator to access the attributes of the structure of the new string run.
I hope I could make my problem clear and thank you in advance for your help!
Best regards
Christian K
1 Comment
Stephen23
on 25 Apr 2019
Meta-data (like test names) is also data, so it should be stored in a variable, not forced awkwardly into variable names. Forcing meta-data into variable names just makes accessing those variables slow, complex, buggy, and hard to debug. Read these to know why:
Accepted Answer
More Answers (0)
Categories
Find more on Structures in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!