Azzera filtri
Azzera filtri

Can you replace names in struct?

5 visualizzazioni (ultimi 30 giorni)
Alexa Z
Alexa Z il 15 Dic 2020
Commentato: J. Alex Lee il 15 Dic 2020
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 Commenti
Alexa Z
Alexa Z il 15 Dic 2020
can we change the yellow name?

Accedi per commentare.

Risposta accettata

J. Alex Lee
J. Alex Lee il 15 Dic 2020
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 Commenti
Alexa Z
Alexa Z il 15 Dic 2020
But the lookup was a different struct, can we get a new column in the EMG struct?
J. Alex Lee
J. Alex Lee il 15 Dic 2020
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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Cell Arrays in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by