Operator '==' is not supported for operands of type 'table'.
이전 댓글 표시
I am tyring to extract each ID for the table attached in the image (table is really large so did not attach the whole table). My code is as follows but I continue to get this error "Operator '==' is not supported for operands of type 'table'." when
A=[c];
R=c(:,"SAPID")
T=transpose(1:127)
u=(unique(R))
TurbineTest1=A(A.SAPID==u(1,1),:);
TurbineTest2=A(A.SAPID==u(2,1),:);
TurbineTest3=A(A.SAPID==u(3,1),:);
TurbineTest4=A(A.SAPID==u(4,1),:);
TurbineTest5=A(A.SAPID==u(5,1),:);
TurbineTest6=A(A.SAPID==u(6,1),:);
TurbineTest7=A(A.SAPID==u(7,1),:);

채택된 답변
추가 답변 (1개)
Peter Perkins
2021년 8월 6일
There are a couple of problems. c is a table, so
R = c(:,"SAPID")
is also a table, with only one variable. A table is a container, so
u = unique(R)
isn't going to work, and even if it did,
A.SAPID == u(1,1)
wouldn't. You want
u = unique(A.SAPID)
Then unique works, and == works. But wait, A.SAPID is a cell array of char, so == is still not going to work. As Scott suggests, you can use strcp. But I'd recommend using a string array for text data, not cell. It might be as simple as using "TextType","string" when you import data.
BUT ACTUALLY, values in SAPID appear to be drawn from a finite set of choices, in other words, they are categorical data. You probably should be using a categorical array.
A.SAPID = categorical(A.SAPID);
Then, all you need to do is iterate over categories(A.SAPID). == just works.
u = categories(A.SAPID);
TurbineTest1 = A(A.SAPID==u(1),:);
BUT HANG ON. Do you really want maybe dozens of separate tables in your workspace? I strongly recommend that you look at things like groupsummary and rowfun to see if you can do operations on groups in your data without pulling it apart.
카테고리
도움말 센터 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!