Can you replace names in struct?

Hello.
Can you replace names in struct? We have 35 rows in a struct with following names
EMG_HRstruct(1).data
EMG_HRstruct(2).data
untill EMG_HRstruct(35).data
TD11 has three files in row 1,2,3 and TD12 has three files in row 4,5,6 and so on.
We have to refer to TD11 for example but it is not in the name of our values from the struct.
CAN WE CHANGE THE NAMES? SO THAT WE CAN REFER TO THE FIRST THREE ROWS FOR TD11?
Thanks.

5 Comments

What are TD11 and TD12 and how are they related to EMG_HRstruct? What does it mean for a "file" to occupy a row?
TD's are subjects and in total 10 but starts with TD3-TD17. EMG data for each subject in the struct, but each EMG data contains 6 columns of muscles. (each TDHR is in a seperate 1x1 struct)
It was each file in a row in the struct overview so each one has a 1x1 struct
can we change the yellow name?

Sign in to comment.

 Accepted Answer

Going out on a limb since as Matt J points out it's not clear what exactly everything is, but...
I think what you need is metadata.
If you don't want to change your basic data type, maybe create an intermediary structure lookup to translate names like TD11 into a list of rows
lookup.TD11 = [1,2,3]
lookup.TD12 = [4,5,6]
...
Then you can access the rows like
target = "TD11"
EMG_HRstruct(loopup.(target)).data
which I guess you will have to somehow cat() together if you don't want the data for each row to be spit out separately.
If you can alter your data structure, maybe consider tabular data with a column for the file group
row|filegrp|data
---+-------+----
1 | TD11 | ...
2 | TD11 | ...
3 | TD11 | ...
4 | TD12 | ...
5 | TD12 | ...
6 | TD12 | ...
7 | TD13 | ...

3 Comments

yes, can we then refer to filegr TD11 in a code? how?
But the lookup was a different struct, can we get a new column in the EMG struct?
Yes you can, but at that point I would use a table instead of a struct array if you want to be able to easily index. Of course you can append a new field to EMG_HRstruct so that you can do
EMG_HRstruct(1).Group = "TD11"
EMG_HRstruct(2).Group = "TD11"
EMG_HRstruct(3).Group = "TD11"
EMG_HRstruct(4).Group = "TD12"
EMG_HRstruct(5).Group = "TD12"
EMG_HRstruct(6).Group = "TD12"
But how will you refer to the appropriate rows by specifying 'TD11'? Unless I am missing something, you'd anyway need to create a temporary variable to identify the appropriate "rows", e.g.
idx = [EMG_HRstruct.Group]=="TD11";
subdata = [EMG_HRstruct(idx).data]; % assuming data can be cat()-ed
or whatever

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 15 Dec 2020

Commented:

on 15 Dec 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!