Legend color not correspondante to plot for a Plot with loop
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
reen2015
le 11 Avr 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 commentaires
reen2015
le 11 Avr 2016
Modifié(e) : reen2015
le 11 Avr 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.
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!