简体   繁体   中英

How to take min and max of a matrix in matlab?

I have something full of numbers like this vee(:,:) . It has 30 rows and 2 columns.

When I try to get the min and max of the second column, I use;

ymax = max(vee(:,2));
ymin = min(vee(:,2)); 

it works

when I want the min and max of the first column, I use

xmax = max(vee(1,:));
xmin = min(vee(1,:));

I don't know about matrix dimensions I might be wrong. Why doesn't the xmin and xmax work? It only gives me the values of the first row. What is wrong here?

in matlab

vee(:,i) % gives you the ith column
vee(i,:) % gives you the ith row

you were doing

vee(:,2) % Right way to access second column
vee(1,:) % Wrong way to access first column, right way to access first row

You need to do

vee(:,1) % Right way to access first column

You should use

xmax = max(vee(:,1));
xmin = min(vee(:,1));

To get the first column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM