Legend color not correspondante to plot for a Plot with loop

1 Ansicht (letzte 30 Tage)
Ferial Assmani
Ferial Assmani am 11 Apr. 2016
Bearbeitet: Ferial Assmani am 11 Apr. 2016
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

Antworten (1)

reen2015
reen2015 am 11 Apr. 2016
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 Kommentare
reen2015
reen2015 am 11 Apr. 2016
Bearbeitet: reen2015 am 11 Apr. 2016
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 am 11 Apr. 2016
Bearbeitet: Ferial Assmani am 11 Apr. 2016
But all legend have the same color ? How distinguished each one ?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by