フィルターのクリア

How to make a structure with numerous(>200) fields with loop?

1 回表示 (過去 30 日間)
JAYYOUNG
JAYYOUNG 2023 年 7 月 4 日
コメント済み: JAYYOUNG 2023 年 7 月 4 日
Hello everyone,
I want to make a structure with fields for each patient, then the cell type(5 by 5) EEG data would be allocated to the fields.
I simply know this way,
S = struct('Pt1',data1,'Pt2',data2,....blablabla)
this makes super long awful code...
I've tried loop like this way but it didn't worked
for i = 1:n
S = struct(strcat('Pt_',num2str(i)),Data(i))
end
please help me :)
  2 件のコメント
Stephen23
Stephen23 2023 年 7 月 4 日
編集済み: Stephen23 2023 年 7 月 4 日
JAYYOUNG
JAYYOUNG 2023 年 7 月 4 日
Thankyou for your help!!

サインインしてコメントする。

採用された回答

Chunru
Chunru 2023 年 7 月 4 日
n= 5;
Data = randi([1 10], [5 1])
Data = 5×1
8 2 1 5 8
for i = 1:n
S.("Pt_"+i) = Data(i);
end
S
S = struct with fields:
Pt_1: 8 Pt_2: 2 Pt_3: 1 Pt_4: 5 Pt_5: 8

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTiming and presenting 2D and 3D stimuli についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by