Getting error All table variables must have the same number of rows.

조회 수: 29 (최근 30일)
Ehtisham
Ehtisham 2024년 5월 23일
이동: Voss 2024년 5월 23일
All table variables must have the same number of rows. while runing the code am getting this error. Need your help
  댓글 수: 4
Voss
Voss 2024년 5월 23일
You can't make a table out of those because they have different number of rows, just like the error message says.
Some of them are empty (0x1) and some are scalars (1x1). That's the problem.
Think about what size they should be, based on your given data, and then figure out why they're not the size they should be.
Ehtisham
Ehtisham 2024년 5월 23일
편집: Voss 2024년 5월 23일
% Ensure all variables have the same length
min_length = min(length(Rpeak_C), length(Tpeak_C), length(L_C), length(Rss_C), length(Ratio_Rpeak_C_Rss_C), length(Delta_C));
% Truncate variables to match the shortest length
Rpeak_C = Rpeak_C(1:min_length);
Tpeak_C = Tpeak_C(1:min_length);
L_C = L_C(1:min_length);
Rss_C = Rss_C(1:min_length);
Ratio_Rpeak_C_Rss_C = Ratio_Rpeak_C_Rss_C(1:min_length);
Delta_C = Delta_C(1:min_length);
% Create the table
PhaseC = table(Rpeak_C, Tpeak_C, L_C, Rss_C, Ratio_Rpeak_C_Rss_C, Delta_C, ...
'VariableNames', {'RpeakC', 'T-peakC', 'L_C', 'RssC', 'RpeakC/RssC', 'Delta_C'});
% Write the table to a CSV file
ligandRemovalFilename = 'PhaseC.csv';
writetable(PhaseC, ligandRemovalFilename)
Used that min length but now giving the Too many arguments error.

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

답변 (1개)

Voss
Voss 2024년 5월 23일
이동: Voss 2024년 5월 23일
If you want to truncate the variables to the size of the smallest one, use size(_,1) which is number of rows, instead of length(_), which is size of the longest dimension.
% Ensure all variables have the same number of rows
min_length = min([size(Rpeak_C,1), size(Tpeak_C,1), size(L_C,1), size(Rss_C,1), size(Ratio_Rpeak_C_Rss_C,1), size(Delta_C,1)]);
% Truncate variables to match the shortest
Rpeak_C = Rpeak_C(1:min_length,:);
Tpeak_C = Tpeak_C(1:min_length,:);
L_C = L_C(1:min_length,:);
Rss_C = Rss_C(1:min_length,:);
Ratio_Rpeak_C_Rss_C = Ratio_Rpeak_C_Rss_C(1:min_length,:);
Delta_C = Delta_C(1:min_length,:);
%Create a separate table for steady state after ligand removal
PhaseC = table( Rpeak_C,Tpeak_C,L_C, Rss_C, Ratio_Rpeak_C_Rss_C,Delta_C, ...
'VariableNames', {'RpeakC' ,'T-peakC' ,'L_C','RssC','RpeakC/RssC','Delta_C',});
% Write the steady state after ligand removal table to a separate CSV file
ligandRemovalFilename = 'PhaseC.csv';
writetable(PhaseC, ligandRemovalFilename);
Note that will produce an empty table in this case.
However, a better solution would be to fix the problem at the source: figure out why variables that should have the same number of rows (if indeed they should) in fact have different numbers of rows.

카테고리

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

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by