'equal' operator does not work on tables
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!