Save variable from struct to excel file

조회 수: 1 (최근 30일)
Mikel  Jimenez
Mikel Jimenez 2021년 12월 2일
댓글: Mikel Jimenez 2021년 12월 5일
Hello,
I have this data.mat file with "errors" and "distractors" variables for 27 participants in three different conditions. I would like to export error data for each participant filtered by condition to three different excel files (one per condition). I am pretty new to Matlab so I am having some difficulties doing this, anyone could advice how to do it?
Thanks in advance,
Mikel
  댓글 수: 1
Mikel  Jimenez
Mikel Jimenez 2021년 12월 2일
I'm trying with:
f=vertcat(data.errors{:,2});
T = array2table(f);
writetable(T,'Name.xls');
but I think I need to include a loop, any ideas?
Thanks,
Mikel

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

채택된 답변

Ive J
Ive J 2021년 12월 2일
You have 3 conditions: each row in 'errors' corresponds to each condition. However, each row in 'distractors' is another matrix of 3X200. You may want to modify this snippet a bit depending on your need.
errors = horzcat(data.errors);
distractors = horzcat(data.distractors);
for i = 1:3
file = "data.cond." + i + ".xlsx";
er = cell2mat(errors(i, :).');
di = cell2mat(distractors(i, :).');
writematrix(er, file, 'Sheet', 'errors')
writematrix(di, file, 'Sheet', 'distractors')
end
  댓글 수: 1
Mikel  Jimenez
Mikel Jimenez 2021년 12월 5일
Fantastic, this works perfectly.
Thanks

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by