Calculate mean of column in structure if another row = 1

4 ビュー (過去 30 日間)
Daniel
Daniel 2014 年 9 月 12 日
コメント済み: Daniel 2014 年 9 月 13 日
I have a structure that has columns Correct (either 0 or 1) and Latency. I am attempting to calculate a mean of the Latency values ONLY if correct = 1. So the Latency mean value from the data set below I am hoping to get is 402
Correct Latency
1 325
0 359
1 410
1 425
0 371
1 448
I have attempted something like this:
if struct.Correct == 1
latmean = mean(struct.Latency)
end
But I get the error "Error using == Too many input arguments"
Any thoughts on a way to achieve this? Thanks
  1 件のコメント
Daniel
Daniel 2014 年 9 月 13 日
As a follow-up question what if I add another array to the cell below
1 0 1 1 0 1
325 359 410 425 371 448
4 4 4 5 5 5
Now is it possible to give an output separately for out=mean(B(2,logical(B(1,:)))) dependent on whether array 3 == 4 or 5?
Thanks

サインインしてコメントする。

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 9 月 12 日
v=[ 1 325
0 359
1 410
1 425
0 371
1 448]
A=struct('correct',num2cell(v(:,1)),'latency',num2cell(v(:,2)))
B=cell2mat(struct2cell(A))
out=mean(B(2,logical(B(1,:))))

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by