Calculate mean of column in structure if another row = 1

3 visualizaciones (últimos 30 días)
Daniel
Daniel el 12 de Sept. de 2014
Comentada: Daniel el 13 de Sept. de 2014
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 comentario
Daniel
Daniel el 13 de Sept. de 2014
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

Iniciar sesión para comentar.

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 12 de Sept. de 2014
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,:))))

Más respuestas (0)

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by