error message : Assignment has more non-singleton rhs dimensions than non-singleton subscripts

3 visualizaciones (últimos 30 días)
Hello,
I have the following problem in Matlab.
Consider the following two datasets:
A = [3, 6, 1, 5, 7 ];
B = [2, 4, 4, 5, 6, 7, 1, 9, 2, 3];
I have to calculate C, which indicates the number of A’s > B. B(1,1)=2, so there are 4 values of A > B(1,1). In that case, C(1,1) has to indicate 4. Etc...
My output dataset has to be the following: C = [4, 3, 3, 2, 1, 0, 4, 0, 4, 3]
In reality, my datasets are much bigger than these. So the datasets above are just an example of my problem.
I have tried the following code, but i get an error
for i=1:10
C(1,i) = A(1,:)>B(1,i);
end
??? Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Thanks in advance
Pieter

Respuesta aceptada

Jan
Jan el 27 de Mayo de 2011
for i=1:10
  C(1,i) = sum(A(1,:) > B(1,i));
end

Vectorized - this will take much more memory, such that it may be slower if your RAM is exhausted:

C = sum(bsxfun('gt', transpose(A), B));

Más respuestas (0)

Categorías

Más información sobre Polar Plots en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by