How To Use Patch In Matlab

Matlab

How can I use PixelLabelImagePatchDatastore. Learn more about pixellabelimagepatchdatastore, image segmentation. Toggle Main Navigation. Discover what MATLAB. How can I use 'patch'. Learn more about patch, trisurf, hold on. Toggle Main Navigation. A triangular surface plot in MATLAB is actually just a patch object.

Active3 years, 7 months ago

Patch Matlab 3d

i'd like to draw sphere using 'patch' function in Matlab.

in function 'patch'vertex=[~~]' in this part, how to choice the point...

And i wonder if possible to draw sphere using 'patch function'..

please help!

jeongjeong

1 Answer

How To Use Patch In Matlab Pdf

Assume you have coordinates for points on the sphere in x, y, and z, as obtained by

Then faces and vertices of a patch object can be obtained using surf2patch:

Finally, it can be plotted:

This approach can be generalized to any function data.

zeeMonkeezzeeMonkeez
4,2903 gold badges21 silver badges44 bronze badges
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.

Not the answer you're looking for? Browse other questions tagged matlabpatch or ask your own question.

Active3 years, 2 months ago

I would like to highlight a specific interval in my plot. I found a way using the patch object.The problem is that my layout gets messy whenever i use it.

Here's an example of a plot:

And to highlight a period:

My results with and without the patch command:

Normal:

Messy:

Look at the fonts and the legend block. Any ideas on how to fix that?

Is there a better way to highlight an interval? I need to choose the color and set transparency.

Just one more question: Why do I have to use the third input (color) if it's not applied?

Thanks in advance!

Alexandre M.Alexandre M.

2 Answers

Edit: This answer is only valid for Matlab versions before 2014b, as the incredibly useful erasemode property has been removed from all HG2 graphic objects on later Matlab versions.

I ran into this problem countless times and I had to learn to live with it. Most times I can accept the glitches of the OpenGL renderer if it buys me nice transparency effects, but in some cases it is just not acceptable.

I use patch objects to highlight intervals in many applications, usually over several curves. There is a trick you can use when transparency is not an option, it is the EraseMode property of the patch object. If you set the EraseMode property to 'xor' the patch will not be transparent, yet anything under the patch will xor the patch pixel colours so you can still see the curves under the patch.

This not being a transparency rendering, you can use the default painter renderer and avoid all the occasional glitches of the OpenGL.

So for example with your data:

Patch

And the nice advantage of this trick is it works with monochrome display/prints. If you cannot use multiple colours, you can use that with only one colour (if you plan black & white printing for publication for example)

HokiHoki
9,8781 gold badge15 silver badges39 bronze badges

(Note: This answer only makes sense if you're using the OpenGL renderer.)

If that's the case, then this is one symptom of

a bug in MATLAB 6.5 (R13) and later versions in the way that axes are rendered in hardware accelerated OpenGL, when transparency is used

as mentioned here.

The simplest workaround is to force OpenGL to run in software mode by including the line:

Apparently, this only works under Windows and Linux. For other symptoms of the problem and different approaches to solutions have a look at this related question.

Regarding your other questions:

Not sure if it's a better way, but it's another option: You could use an area-plot like this:

However, OpenGL renderer will also cause problems here, so it's not a fix, just another option.

And finally, I'm not sure what you mean by the color not being used. The 'facecolor' is used, that's why your plot is green. When you go through the area-option above step by step you'll see that you get a solid color first. Later on, transparency is added with the 'facealpha'-option.

Community
Franz WurstFranz Wurst

Not the answer you're looking for? Browse other questions tagged matlabhighlight or ask your own question.