Custom Plot with matlab
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Emin BAKIR
am 9 Mai 2016
Beantwortet: Emin BAKIR
am 14 Mai 2016
I need to draw a custom plot with in Matlab, actually I will combine 4 different graph in one, with the following scenario Let say, I run an application for 4 times, the values goes to X axis will always be same, so for each run, x1=x2=x3=x4=[1 2 3 4];
For every x point there will be a y point, an element of set A=('a','b','c'),
Let say for each run the corresponding Y values are: y 1=['a' 'b' 'a' 'c']; y2=['a' 'a' 'b' 'c']; y3=['c' 'a' 'a' 'a']; and y4=['a' 'b' 'c' 'a']; with these values I want to draw a figure which combines all 4 runs in one chart. I want to represent the Y values as a 1 unit tall (actually its height is not that much matter) coloured vertical line, instead of just points. The following image demonstrated the figure I want to draw, anyone knows a way to achieve this? Thanks
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/163864/image.png)
0 Kommentare
Akzeptierte Antwort
KSSV
am 10 Mai 2016
clc; clear all ;
% Set colors
a = 'g' ; b = 'r' ; c = 'y' ;
c1 = [{a} {b} {a} {c}] ;
c2 = [{a} {b} {b} {c}] ;
c3 = [{c} {a} {a} {a}] ;
c4 = [{a} {b} {c} {a}] ;
c = [c1 ; c2 ; c3; c4] ;
% Make grid
x = linspace(0,1,5) ;
y = linspace(0,1,5) ;
[X,Y] = meshgrid(x,y) ;
% Plot
figure
pcolor(X,Y,NaN(size(X)))
hold on
for i = 1:4
for j = 1:4
plot([X(i,j),X(i+1,j)],[Y(i,j),Y(i+1,j)],c{i,j},'linewidth',5)
end
end
axis off
xlim([x(1) x(end-1)])
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Line Plots 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!