Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot square surface in Matlab

Tags:

plot

matlab

How to plot a square surface in Matlab?

More exactly I want to plot a square square with value 0.5 surface which is located at X:-1 to X=1 and Y:2.5 to 3.5.

I tried the following

[X,Y] = meshgrid(-3.5:.5:3.5);
Z = zeros(15);
Z(end-2:end,5:9) = 0.5;
surf(X,Y,Z);

This doesn't result in a perpendicular edge. How to archive that?

like image 923
Razer Avatar asked Dec 03 '25 14:12

Razer


1 Answers

This is what the patch function is for.

Matlab documentation

so for your case:

X = [ -1  -1   1   1];
Y = [3.5 2.5 2.5 3.5];
Z = [0.5 0.5 0.5 0.5];

patch(X,Y,Z,'red')
view(45,45)

example

like image 130
Robert Seifert Avatar answered Dec 06 '25 08:12

Robert Seifert