Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Compare results of three cells

1 回表示 (過去 30 日間)
Lucas Neves
Lucas Neves 2017 年 3 月 5 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
So here it's the thing. I have three cells, each one with a data of 120 values (1x120 double) and i need to compare the 1st value of the first cell with the 1st one of the second cell and the 1st one of the third cell, then the 2nd one of the first cell with the 1st one of the second cell with the 2nd one of the third cell and so on until i compare the 120 numbers of the three cells. Any ideas? Thanks in advance! Have a good day!
  1 件のコメント
kowshik Thopalli
kowshik Thopalli 2017 年 3 月 5 日
編集済み: kowshik Thopalli 2017 年 3 月 5 日
Can you expand on your 'comparing;. Are you comparing equality? or whichever is greater or smaller? or if the (value1-value2)<tolerance?

回答 (2 件)

kowshik Thopalli
kowshik Thopalli 2017 年 3 月 5 日
Assuming you wish to find the maximum of the corresponding elements in each cell
cell1={rand(1,120)};
cell2={rand(1,120)};
cell3={rand(1,120)};
foo=cellfun(@max, cell,cell2,'UniformOutput',false);
final=cellfun(@max,foo,ceff3,'UniformOutput',false)
hope this helps
  2 件のコメント
Lucas Neves
Lucas Neves 2017 年 3 月 5 日
Almost there mate. Let me try to make an example for you
y1=[1 %120 numbers
-1
-1
1]
y2= [-1 %120 numbers
1
-1
-1]
y3=[-1 %120 numbers
-1
1
-1]
So the final answer would be
x= [1 %The positive value indicates where the x must belong
2
3
1]
Jan
Jan 2017 年 3 月 5 日
@Lucas: Your variables are not cells, but double vectors. This detail matters.

Jan
Jan 2017 年 3 月 5 日
y1 = [ 1; -1; -1; 1];
y2 = [-1; 1; -1; -1];
y3 = [-1; -1; 1; -1];
[ignore, index] = max([y1, y2, y3], [], 2);
Now index contains the wanted result. If the variables are really cells:
[ignore, index] = max([y1{1}, y2{1}, y3{1}], [], 2);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by