필터 지우기
필터 지우기

Custom Plot with matlab

조회 수: 2 (최근 30일)
Emin BAKIR
Emin BAKIR 2016년 5월 9일
답변: Emin BAKIR 2016년 5월 14일
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

채택된 답변

KSSV
KSSV 2016년 5월 10일
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)])

추가 답변 (1개)

Emin BAKIR
Emin BAKIR 2016년 5월 14일
Thank you Siva, It helped. Cheers

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by