subtracting columns of one matrix from the other and chaining the awnsers
1 view (last 30 days)
Show older comments
i have a matrix A=[1,2,3; 4,5,6 ; 7,8,9] and matrix B=[10,20,30,40; 10,20,30,40; 10,20,30,40]
i want to substract A(:,1)-B and chain it to A(:,2)-B and so on.
without using a loop!
any ideas??
0 Comments
Answers (1)
Image Analyst
on 24 Nov 2021
What is your definition of "chain"? Do you mean concatenate?
A(:, 1) is a column vector while B is a matrix. Were you planning on using automatic expansion?
A=[1,2,3; 4,5,6 ; 7,8,9]
B=[10,20,30,40; 10,20,30,40; 10,20,30,40]
% "i want to substract A(:,1)-B and chain it to A(:,2)-B and so"
m1 = A(:,1) - B
m2 = A(:, 2) - B
% Concatenate m1 to the right of m2
output = [m2, m1]
0 Comments
See Also
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!