Non-singleton dimensions of the two input arrays must match each other.

11 views (last 30 days)
a = {rand(6000,7); rand(3600,7); rand(600,7)};
mx = {randi(50,600,1), randi(50,600,1); randi(50,360,1), randi(50,360,1); randi(50,60,1), randi(50,60,1)};
mn = {randi(50,600,1), randi(50,600,1); randi(50,360,1), randi(50,360,1); randi(50,60,1), randi(50,60,1)};
q = mx;
for x = 1:size(q,1)
for y = size(mn,2)
b = reshape(a{x}(:,7),10,[]).';
b = bsxfun(@minus,b,mn{x,y});
b = bsxfun(@rdivide,b,mx{x,y}-mn{x,y});
q{x,y} = reshape(b.',[],1);
end
end
I want to change the following line b = reshape(a{x}(:,7),10,[]).' into b = transpose(reshape(a{x}(:,7),60,[]).') but I get an error even though both reshaping commands give me a 60 x 10 double.
Error using bsxfun Non-singleton dimensions of the two input arrays must match each other.
Where is my mistake?

Accepted Answer

Stephen23
Stephen23 on 3 Dec 2014
Edited: Stephen23 on 3 Dec 2014
You wish to perform an array transpose on the following line:
b = reshape(a{x}(:,7),10,[]).';
However this line already has a transpose operation .' at the end. So transposing it twice is simply equivalent to not transposing it:
b = reshape(a{x}(:,7),10,[]);
In any case, the error is telling you that the two input matrices provided to the function bsxfun must match in size on all dimensions that are not singleton. Have a look at the dimensions of the arrays used as inputs to bsxfun. Do these fit the requirements of the documentation?
You should learn to use some debugging tools , then you could figure out for yourself where this error is occurring.
  5 Comments
AA
AA on 3 Dec 2014
thanks for giving me the hint. the above code is what i wanted. i just removed the .'
Stephen23
Stephen23 on 3 Dec 2014
Edited: Stephen23 on 3 Dec 2014
Glad to be of assistance. This wasn't hard to track down, because the error message is pretty explicit: perhaps revising debugging in MATLAB would be worth your while.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!