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!