Operator '==' is not supported for operands of type 'table'.
19 ビュー (過去 30 日間)
古いコメントを表示
Patrick Lonergan
2021 年 8 月 6 日
コメント済み: Patrick Lonergan
2021 年 8 月 7 日
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),:);

0 件のコメント
採用された回答
その他の回答 (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.
参考
カテゴリ
Help Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!