Plot 2 1x4 matrices
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Anastasia Zistatsis
am 4 Feb. 2021
Bearbeitet: the cyclist
am 4 Feb. 2021
I'm trying to plot these two matricies: x = [1 4 4 1]; y = [1 1 4 4];
They're supposed to be coordinates to create this ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/509797/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/509797/image.png)
I know it's probably a very simple solution, but whatever plot attempt I make, only a line shows up on the graph. Please let me know! Thank you
0 Kommentare
Akzeptierte Antwort
the cyclist
am 4 Feb. 2021
Bearbeitet: the cyclist
am 4 Feb. 2021
Here is one way:
x = [1 4 4 1];
y = [1 1 4 4];
figure
patch(x,y,'b')
set(gca,'XLim',[0 5],'YLim',[0 5])
That last line is only to show create a little space around the rectangle.
3 Kommentare
the cyclist
am 4 Feb. 2021
Bearbeitet: the cyclist
am 4 Feb. 2021
Please be more specific than "it doesn't work". Does it give an error message? Does it show something unexpected?
But, I'll make a guess here, that the second patch replaced the first one, which is the default behavior. You can use the hold command:
x = [1 4 4 1];
y = [1 1 4 4];
x2 = [1 3 3 1];
y2 = [1 1 3 3];
figure
hold on
patch(x,y,'b')
patch(x2,y2,'r')
set(gca,'XLim',[0 5],'YLim',[0 5])
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!