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

3 views (last 30 days)
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

Jan
Jan on 27 May 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));

More Answers (0)

Categories

Find more on Polar Plots in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!