How to plot a patch?
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a plot, but I want to crop a rounded rectangle area from it. For example I have a sinusoid plane wave image plot, and I want to draw only part of it, a rounded rectangle area. Is it posible to do it easily?
2 Commenti
bio lim
il 28 Nov 2016
Can you give the code for your rectangle plot so that I can take a look at it?
Risposte (2)
Star Strider
il 17 Dic 2016
Try this (and a short tutorial on the patch funciton):
The Code —
x = linspace(0, 2*pi, 1000);
y = sin(x);
sub_area_idx = [find((y <= 0.5) & (x <= pi)) find((y >= -0.5) & ((x > pi) & (x <= 2*pi)))];
figure(1)
plot(x,y,'r')
hold on
patch(x([sub_area_idx, flip(sub_area_idx)]), [y(sub_area_idx), zeros(size(sub_area_idx))], 'g')
hold off
grid
The ‘x’ (independent variable) and ‘y’ (dependent variable) together define the entire sine curve. I arbitrarily chose ± ½ as the amplitude for the patch. The ‘sub_area_idx’ are indices into both ‘x’ and ‘y’ for those criteria.
In the patch call, the independent variable ‘x’ has to ‘retrace its steps’ (thus the flip call) to complete the curve, while the dependent variable ‘y’ only has to define those ‘retraced steps’ as zero, since (by our definition here) the patch only exists between the ‘x’-axis and ‘y’ at any particular point.
I’m not certain what you want to do, but this should at least get you part way there.
The Plot —

0 Commenti
Farouk Moukaddem
il 13 Dic 2016
Hi Mr M,
You can use the "imcrop" function to create an interactive image cropping tool associated with the image displayed in your current figure.
The following command can be used to crop the image "I" according to the cropping rectangle "rect"
>>imcrop(I,rect)
"rect" is a four-element position vector of the form [xmin ymin width height] that specifies the size and the position of the crop rectangle. To obtain the coordinates of the rectangle that you would like to crop, you can use the "getrect" function to obtain these values.
Refer to the following documentation links for more information:
Thanks,
Farouk
0 Commenti
Vedere anche
Categorie
Scopri di più su Polygons in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!