How can i solve the issue of struct2table
조회 수: 28 (최근 30일)
이전 댓글 표시
For a while now, i've been trying to implement the struct2table command in my code to like get my simulated variables in form f table but it has been futile despite watching,reading and trying all i have seen, still no postitive change. i need help, probably there is something i am not doing the right way until now.
intlinsol is a 768 x 1 (these are binary integers numbers of 1's and 0's) i got after simulating about 16 variables which has 48 binary enteries (of 1's and 0's) each
so then i wrote this:
tbl=struct2table(intlinsol);
vars= {'xwm1','xwm2','xdw1','xdw2','xvc1','xvc2','xmw','xtt','xsi','xest1','xest2','xov','xtm','xtd1','xtd2','xrf','uwm1','uwm2','udw1','udw2','uvc1','uvc2','umw','utt','usi','uest1','uest2','uov','utm','utd1','utd2','urf'};
outputvars= stack(tbl,vars,'NewDataVariableName','Amt','IndexVariableName','Var')
this is what matlab says:
"Error using struct2table (line 33) , Input structure must be a scalar structure, or a structure array with one column or one row."
Error in realmodifiedcode (line 213)
tbl=struct2table(intlinsol);
댓글 수: 0
답변 (2개)
Matt J
2021년 5월 30일
편집: Matt J
2021년 5월 30일
I don't know why you think struct2table is relevant to this problem if intlinsol is not a struct. You have also not described how the 16 variables are distributed over the 768 elements of linsol. If each successive group of 48 elements belong to one of the 16 variables, then you could build tbl as follows:
tbl=array2table( reshape(intlinsol,[],16) )
You then present 32 variable names vars in your code rather than the 16 that you say you have. Not sure how those are related to anything.
댓글 수: 3
Steven Lord
2021년 5월 30일
You described intlinsol as "intlinsol is a 768 x 1 (these are binary integers numbers of 1's and 0's)" which to me implies that it is a logical or double vector. In that case, struct2table is not the right tool to convert that into a table array, since intlinsol is not a struct. Just call table on it to create a 768-by-1 table.
v = randi(5, 8, 1)
t = table(v)
댓글 수: 8
Steven Lord
2021년 5월 31일
Since that doesn't sound really related to the topic of this question you should ask it as a separate question with a descriptive title.
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!