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

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Jan
Jan il 27 Mag 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));

Più risposte (0)

Categorie

Scopri di più su Polar Plots in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by