Operator '==' is not supported for operands of type 'table'.

51 次查看(过去 30 天)
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),:);

采纳的回答

Scott MacKenzie
Scott MacKenzie 2021-8-6
Try this:
TurbineTest1=A(strcmp(A.SAPID,u(1,1)),:);

更多回答(1 个)

Peter Perkins
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 CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by