Comparing ones in a table
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Kevin Holly
il 13 Ott 2021
Modificato: Kevin Holly
il 13 Ott 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 Commenti
Vedere anche
Categorie
Scopri di più su Tables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!