필터 지우기
필터 지우기

Legend color not correspondante to plot for a Plot with loop

조회 수: 1 (최근 30일)
Ferial Assmani
Ferial Assmani 2016년 4월 11일
편집: Ferial Assmani 2016년 4월 11일
Dear all, even using 2016a version i have a problem in legend color which are not correspondante to plot for a plot with loop, this is my code
V_Time = [1, 2, 3]; % Time Vector fixe length
%
V_Data = 1:1:12; % Data Vector
Nbr_Position = 2; % Nbr of position
Nbr_Case = 2; % Nbr of cases
%
N_Rows= length(V_Time); % Nbr of rows for matrix
N_columns= length(V_Data)/N_Rows; % Nbr of columns for matrix
M_Brut= (reshape(V_Data,[N_Rows,N_columns])); % Brut matrix from Data Vector
%
%
for i=1:Nbr_Position % loop by position
M_Nett{i} = M_Brut(:,(i):(Nbr_Position):(end)); % Nett matrix
figure
for j=1:Nbr_Case % loop by case
plot(V_Time',M_Nett{i}(:,1:j)) % plot pair
hold on
end
title(['Position N°: ' num2str(i)]) % title
legend(genvarname(repmat({'Case'},1,Nbr_Case),'Case')) % legend
end
This is the result plot

답변 (1개)

reen2015
reen2015 2016년 4월 11일
Hi
it must be because the color is changing per iteration as you didnt specify any color in plot. Try specifying color like plot(x,t,'b') for each case separately, so as to make sure the same color appears in legend.
Good luck
Raina
  댓글 수: 3
reen2015
reen2015 2016년 4월 11일
편집: reen2015 2016년 4월 11일
I did this
clc;clear all;close all;
V_Time = [1, 2, 3]; % Time Vector fixe length
%
V_Data = 1:1:12; % Data Vector
Nbr_Position = 2; % Nbr of position
Nbr_Case = 2; % Nbr of cases
%
N_Rows= length(V_Time); % Nbr of rows for matrix
N_columns= length(V_Data)/N_Rows; % Nbr of columns for matrix
M_Brut= (reshape(V_Data,[N_Rows,N_columns])); % Brut matrix from Data Vector
%
%
for i=1:Nbr_Position % loop by position
M_Nett{i} = M_Brut(:,(i):(Nbr_Position):(end)); % Nett matrix
figure
for j=1:Nbr_Case % loop by case
if i==1
plot(V_Time',M_Nett{i}(:,1:j),'c') % plot pair
hold on
end
if i==2
plot(V_Time',M_Nett{i}(:,1:j),'r') % plot pair
hold on
end
end
title(['Position N°: ' num2str(i)]) % title
legend(genvarname(repmat({'Case'},1,Nbr_Case),'Case')) % legend
end
But I could not separate cases as i couldnt figure out your cases.
Ferial Assmani
Ferial Assmani 2016년 4월 11일
편집: Ferial Assmani 2016년 4월 11일
But all legend have the same color ? How distinguished each one ?

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by