'equal' operator does not work on tables

조회 수: 12 (최근 30일)
Tobias Kleinert
Tobias Kleinert 2022년 5월 11일
댓글: Tobias Kleinert 2022년 5월 11일
Hi all,
I have a 14x9 table called TABLE (it is type table) containing variables of different types (strings and numbers) in each of the 9 columns. Now i would like to apply an 'if' function to the table, which loops over the 14 rows of the table in column 9, and writes ones in a NEWFILE for values = 1, and zeros otherwise. The problem is that I get the error message:
Incorrect use of '=' operator. Assign a value to a variable using '=' and compare values for equality using '=='.
Here's what I got:
for TABLEheight = 1:height(TABLE) %loop through rows of TABLE
if (TABLE(TABLEheight,9)) = 1 %if rule applies...
NEWFILE(TABLEheight,1) = 1 %write ones in NEWFILE
else
NEWFILE(TABLEheight,1) = 0 %otherwise write zeros
end
end
So the main problem I have is that I can't use the = operator using tables. Any ideas how I can solve this problem?
Thanks,
Tobi

답변 (1개)

KSSV
KSSV 2022년 5월 11일
You need not to un a loop. You can get it with one go using ==. Let T1, T2 be your tables, and you want to comapare 9 the column.
idx = T1.(9)==T2.(9)
  댓글 수: 2
Tobias Kleinert
Tobias Kleinert 2022년 5월 11일
Thank you so much for the answer, but I don't quite get it... I don't want to compare columns of different tables, I only want to check values of one specific column in ONE table and create a new file with a correpsonding column that gives out 1s if a criterion is met, and zeros if the criterion is not met...
Sorry for the misunderstanding
Tobias Kleinert
Tobias Kleinert 2022년 5월 11일
Here's the table I use (it's different from the exemplary table I posted earlier). The relevant column is column 9 (urevent), where I look for ones. I want a new table (or other type) that displays 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 in the first column (as there is indeed a 'one' somewhere in column 9 of the original table. Hope this makes my question more understandable?

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

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by