How can I export variales from double and structure with different rows into excel?

조회 수: 3 (최근 30일)
Hello everyone,
I have variables in 8x1 double, in 40x1 double under 1x1 struct, and 1x1 double. Since I have the same varibles for different trials saved in different MATLAB files, I was trying to save all the variables from each trial in a table first and export to a excel for all trials. Then, copy and paste variables from each excel for each trial, and put them all together in a new excel. But when I run the code for making a table (as shown below), it gets into an error:
Error using table (line 233)
All table variables must have the same number of rows.
KineVar=table(AbdAngleMax,AbdAngleMin,AbdAngleChange,speed,FinSwingDist.dist,TailSwingDist.dist)
EMGvariable.Properties.VariableNames{1} = 'AbdAngleMax';
EMGvariable.Properties.VariableNames{2} = 'AbdAngleMin';
EMGvariable.Properties.VariableNames{3} = 'AbdAngleChange';
EMGvariable.Properties.VariableNames{4} = 'speed';
EMGvariable.Properties.VariableNames{5} = 'FinSwingDist.dist';
EMGvariable.Properties.VariableNames{5} = 'TailSwingDist.dist';
fileName='KINEvariableResults.xlsx'
writetable(KINEvariable,fileName)
winopen(fileName)
Is there anything I could do to fix the issue? Or should I not use the table function?
Thank you very much for your help!
  댓글 수: 3
lisa Liang
lisa Liang 2020년 10월 1일
Thank you for your answer! Yes, you are right.
"AbdAngleMax","AbdAngleMin","AbdAngleChange" are in 8x1 double, and "FinSwingDist.dist","TailSwingDist.dist" are in in 40x1 double of a 1x1 struct,
"speed" is in 1x1 double.
Do you mean that I should turn the 1x1 and 8x1 doubles into 40x1 double and fill it up with NaNs?
Mario Malic
Mario Malic 2020년 10월 1일
편집: Mario Malic 2020년 10월 1일
Yes, that should work.
Edit: moving my comment to answers, since I tested it.

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

채택된 답변

Mario Malic
Mario Malic 2020년 10월 1일
These have to have same number of rows, which they don't, according to your first sentence.
AbdAngleMax,AbdAngleMin,AbdAngleChange,speed,FinSwingDist.dist,TailSwingDist.dist
Fill up your variables with NaN's to match the maximum number of rows that a variable has.
  댓글 수: 3
Mario Malic
Mario Malic 2020년 10월 1일
편집: Mario Malic 2020년 10월 1일
If you know that maximum number of rows is 40, initialize it with NaN, if that would not make a problem in your calculations
AbdAngleMax = NaN(40,1)
Otherwise,
L = length(AbdAngleMax)
AbdAngleMax(L+1:40,1) = nan;
% repeat for the rest of variables/structs

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

추가 답변 (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