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

조회 수: 88 (최근 30일)
Patrick Lonergan
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),:);

채택된 답변

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.
  댓글 수: 1
Patrick Lonergan
Patrick Lonergan 2021년 8월 7일
Thanks for the help. I will look into the your suggestions

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

카테고리

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