Legend - for plots in if condition
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
for j = 1:laenge4(1,2)
if isempty(TempVolt(j).data) == true;
else
x_axes = volt_data(:,1);
y_axes = time_data(:,2);
if volt_data(1)== 7
a1 = plot(x_axes,y_axes,'bs','DisplayName','@7V');
hold on;
end
if volt_data(1)== 13.5
a2 = plot(x_axes,y_axes,'gs','DisplayName','@13.5V');
hold on;
end
if volt_data(1)== 18
a3 = plot(x_axes,y_axes,'ks','DisplayName','@18V');
hold on;
end
end
end
l = legend('show')
set(l, 'Interpreter','none');
But I want to display all 3 legends even if the plots a2 and a3 are not plotted. Can anyone please help me. Becoz in for loop for other values of 'i' a2 or a3 can be plotted.
Please help me
0 Commenti
Risposte (1)
Jan
il 30 Giu 2015
What about setting the visibility?
for j = 1:laenge4(1,2)
if ~isempty(TempVolt(j).data)
x_axes = volt_data(:,1);
y_axes = time_data(:,2);
a1 = plot(x_axes,y_axes,'bs','DisplayName','@7V', ...
'Visible', OnOffStr(volt_data(1) == 7));
hold on;
a2 = plot(x_axes,y_axes,'gs','DisplayName','@13.5V', ...
'Visible', OnOffStr(volt_data(1)== 13.5));
a3 = plot(x_axes,y_axes,'ks','DisplayName','@18V', ...
'Visible', OnOffStr(volt_data(1)== 18));
end
end
function S = OnOffStr(V)
if V
S = 'on';
else
S = 'off';
end
Does this works or do invisible line vanish from the legend?
2 Commenti
Jan
il 4 Lug 2015
Function definitions are allowed inside function M-files, not in scripts and not in the command window. So either create a new file called OnOffStr.m and store it in a user-defined folder inside your Matlab path. Or append teh definition of the function to your function file. If you use a script currently, think of converting it to a function.
Vedere anche
Categorie
Scopri di più su Legend in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!