Appending a table to another index error

조회 수: 1 (최근 30일)
farzad
farzad 2020년 11월 9일
댓글: Peter Perkins 2020년 11월 20일
Hi all
I am appending a table to another one during a loop, every time I calculate the first one in each cycle.
this is the error I get
Subscripting into a table using one subscript (as in t(i)) or three or more subscripts (as in t(i,j,k)) is not supported. Always specify a row subscript and a variable subscript, as in t(rows,vars).
Elapsed time is 21.683230 seconds.
and this is my code :
fn = cell2table(Tc, 'VariableNames', table_without_header.Properties.VariableNames);
if f1==1
Tout{1}=[fn];
else
Tout{f1} = [Tout{f1-1};fn];
end
fn is a 9x1 table and I think after the first loop, that also Tout becomes a 9x11 table I get this problem. how to resolve it ?

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 11월 9일
편집: Cris LaPierre 2020년 11월 9일
The error explains the issue. You have to specify row and column. Try this (untested):
if f1==1
Tout{1,:}=[fn];
else
Tout{f1,:} = [Tout{f1-1,:};fn];
end
Unless it was a typo, there appears to be an issue with the number of columns in fn (9x1) and Tout (9x11). They will both have to have the same number of columns for this code to work.
  댓글 수: 1
Peter Perkins
Peter Perkins 2020년 11월 20일
This code might run (although I don't think it will), but it seems hard to imagine that this is what you want. You say that "fn is a 9x1 table", and then "Tout becomes a 9x11 table". So how can a 9x1 table be stored in one row of another table? And why is each row of Tout apparently supposed to be an incrementally growing table?
This can't be right.
Are you trying to store each new instance of fn in a cell of a cell array? Or trying to concatenate all the tables vertically? I imagine if it's the latter, you want something more like
Tout = [Tout; fn]
at each iteration of your loop, but you haven't even shown any code with a loop in it.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by