How to save data at each iteration in a cell array?

Hi,
I have saved data sests where i have two variables of 3-D, A and B. I want to load it for each subject and save it in a cell array, as the variables have the same name for each subject. But the size is varied across each subject.
How can i do that.?
I am doing following:
for subject= 1:2
resultFileName = sprintf('Sub0%i_Epochs.mat',subject); % generate result filename
load(resultFileName)
A_Epochs{:,:,:}= epochs([1: size(epochs,1)/2],6,:);
B_Epochs{:,:,:}= epochs([size(epochs,1)/2+1:end],6,:);
end

3 件のコメント

Rik
Rik 2020 年 4 月 17 日
It is not entirely clear to me what you mean. Do you mean something like this?
N_subjects=2;
A_Epochs=cell(1,N_subjects);
B_Epochs=cell(1,N_subjects);
for subject= 1:N_subjects
resultFileName = sprintf('Sub0%i_Epochs.mat',subject); % generate result filename
S=load(resultFileName);
A_Epochs{subject}=S.A;
B_Epochs{subject}=S.B;
end
Joana
Joana 2020 年 4 月 17 日
Thanks for you reply Rik.
I got it.
i need to take 'Mean' of cell array of A_Epochs and B_Epochs separately. I am new to MATLAb so i don't know how to do that.?
Can you help please.?
Rik
Rik 2020 年 4 月 17 日
This question was continued here.

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

 採用された回答

Walter Roberson
Walter Roberson 2020 年 4 月 17 日

0 投票

A_Epochs{subject}= epochs([1: size(epochs,1)/2],6,:);
B_Epochs{subject}= epochs([size(epochs,1)/2+1:end],6,:);

3 件のコメント

Walter Roberson
Walter Roberson 2020 年 4 月 17 日
your epochs variable does not have multiple columns.
Walter Roberson
Walter Roberson 2020 年 4 月 17 日
編集済み: Walter Roberson 2020 年 4 月 17 日
N_subjects=2;
A_Epochs=cell(1,N_subjects);
B_Epochs=cell(1,N_subjects);
for subject= 1:N_subjects
resultFileName = sprintf('Sub0%i_Epochs.mat',subject); % generate result filename
S=load(resultFileName);
A_Epochs{subject} = S.epochs(1:end/2,6,:);
B_Epochs{subject} = S.epochs(end/2+1:end,6,:);
end
Joana
Joana 2020 年 4 月 17 日
Thanks for you reply Walter.
I got it.
i need to take 'Mean' of cell array of A_Epochs and B_Epochs separately. I am new to MATLAb so i don't know how to do that.?
Can you help please.?

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

質問済み:

2020 年 4 月 17 日

コメント済み:

Rik
2020 年 4 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by