简体   繁体   中英

Neat way of generating rectangle coordinates from two corner points?

I'm plotting a box in Matlab from four coordinates. Is there a neater way to generate these vectors than writing them out explicitly?

plot( ...
    [x_min x_max; x_min x_max; x_min x_min; x_max x_max], ...
    [y_min y_min; y_max y_max; y_min y_max; y_min y_max], ...
    '-r' );

In my case, the variables are called lat_min and ax_min , which means that the above lines won't fit into 80 characters. And I'd really like that, since I'm going to print the code.

How about using rectangle :

pos = [ax_min, lat_min, ax_max - ax_min, lat_max - lat_min];
rectangle('Position', pos, 'EdgeColor', 'r')

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