필터 지우기
필터 지우기

Can you replace names in struct?

조회 수: 5 (최근 30일)
Alexa Z
Alexa Z 2020년 12월 15일
댓글: J. Alex Lee 2020년 12월 15일
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
Alexa Z
Alexa Z 2020년 12월 15일
Alexa Z
Alexa Z 2020년 12월 15일
can we change the yellow name?

댓글을 달려면 로그인하십시오.

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by