How to plot a patch?
28 views (last 30 days)
Star Strider on 17 Dec 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)))];
patch(x([sub_area_idx, flip(sub_area_idx)]), [y(sub_area_idx), zeros(size(sub_area_idx))], 'g')
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 —
Farouk Moukaddem on 13 Dec 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"
"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: