subtracting matrices in a special way
1 view (last 30 days)
Show older comments
a = randi(50,600,9);
mx = randi(50,60,1);
q = bsxfun(@minus,reshape(a(:,7),10,[]),mx);
q = reshape(q,[],1);
After reshaping and cutting the variable 'a' into 10 blocks I want the first mx value to be subtracted from the first block of ten, the second mx value from the second block of 10, the third mx value from the third block of 10 and so on.... How can I implement these changes in my bsxfun function?
thanks
7 Comments
Stephen23
on 1 Dec 2014
PS: Is there a purpose to creating a huge array a and then using only the seventh column from it?
Accepted Answer
More Answers (1)
Andrei Bobrov
on 1 Dec 2014
Edited: Andrei Bobrov
on 1 Dec 2014
a = randi(50,600,9);
mx = randi(50,60,1);
a7 = reshape(a(:,7),10,[]);
out0 = bsxfun(@minus,a7,mx(:)');
out = out0(:);
or
out = a(:,7) - mx(ceil((1:size(a,1))/numel(mx)));
See Also
Categories
Find more on Computer Vision with Simulink 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!