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

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

 Accepted Answer

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));

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

No tags entered yet.

Asked:

on 27 May 2011

Community Treasure Hunt

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

Start Hunting!