Comparing ones in a table
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
I have 2 different 1x1 struct with 4 fields in matlab where each fields ccontains 5 different a 103x5 table. I which to compare colum 3 and 5 in each of these fields for both struc. Both colums contains 1's and 0's and i want to have a output a vector that has gives a output 1 when both elemet of these colum is 1. So lets say,
A= [0 1 1 0 1 1 1]
B= [1 1 0 0 0 1 1]
I want the new vector to be
Output = [0 1 0 0 0 1 1]
Is there a smatter way then using if statement for each field ?
0 件のコメント
回答 (1 件)
Kevin Holly
2021 年 10 月 13 日
編集済み: Kevin Holly
2021 年 10 月 13 日
Here is one way of doing it.
t = table;
t.column1 = randi([0 1],[7 1]);
t.column2 = randi([0 1],[7 1]);
t.column3 = [0 1 1 0 1 1 1];
t.column4 = randi([0 1],[7 1]);
t.column5 = [1 1 0 0 0 1 1];
s.table = t;
Output = s.table.column3 == s.table.column5 & s.table.column3 + s.table.column5 ~= 0
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!