![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/355079/image.jpeg)
filling a 1D plot with colours associated to each sample value
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I plotted a 1D signal in Matlab, and then I want to show the value of each specific sample by a district colour. something like what "imagesc" command does for 2D plots. I attached an example of what is in my mind. Any suggestions, please?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/355046/image.png)
0 Kommentare
Antworten (1)
Abdolkarim Mohammadi
am 2 Sep. 2020
Bearbeitet: Abdolkarim Mohammadi
am 2 Sep. 2020
You can use patch() and use your response values for both edges and the color data. You replace your data with SampleX and SampleY.
SampleX = (1220:1250)';
SampleY = rand (numel(SampleX), 1);
PatchX = vertcat (SampleX, flip(SampleX));
PatchY = vertcat (SampleY, zeros(numel(SampleY),1));
ColorData = vertcat (SampleY, flip(SampleY));
patch (PatchY, PatchX, ColorData);
colorbar ();
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/355079/image.jpeg)
Siehe auch
Kategorien
Mehr zu Polygons 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!