I need help about writing a script to get a vector consisting of Max and min for each column in a matrix.
Show older comments
Suppose having a matrix A= [1 2 3;4 5 6; 7 8 9] you need a vector B = [ min a(colmn1) max a(column 2) min a(column)] B =[1 6 7]
Answers (1)
Azzi Abdelmalek
on 22 Jun 2015
Edited: Azzi Abdelmalek
on 22 Jun 2015
A= [1 2 3;4 5 6; 7 8 9]
B=[min(A(:,1)) max(A(:,2)) min(A(:,3))]
But in your case you mean max or min in rows, not in column.
B=[min(A(1,:)) max(A(2,:)) min(A(3,:))]
If your matrix is big
A= [1 2 3;4 5 6; 7 8 9];
B=zeros(1,size(A,2));
B(1:2:end)=min(A(1:2:end,:),[],2)';
B(2:2:end)=max(A(2:2:end,:),[],2)'
Categories
Find more on Aerospace Blockset 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!