Comparing ones in a table
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Kevin Holly
am 13 Okt. 2021
Bearbeitet: Kevin Holly
am 13 Okt. 2021
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 Kommentare
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!