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

3 次查看(过去 30 天)
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

采纳的回答

Jan
Jan 2011-5-27
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));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Polar Plots 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by