strange for useing ' legend'

Dear, I used the following code to draw a figure. But the 'legend' didn't work well .I have used similar code for all drawing figures ,only for one didn't work. Please give me a hand! I really appreciate your help!
Best! xinjie
% % clear clc linestr={'ko','y*','rh','bs','K-','y-','r-','b-','g-','k--p','b--o','y--s','g--*','r--d','g-.h','g-.p'}; % linestr={'k-o','b-s','y-*','g-d','r-h','k-.o','b-.s','y-.*','g-.d','r-.h','k--p','b--o','y--s','g--*','r--d','g-.h','g-.p'}; linewidth = 1.5; data1=importdata('test.txt'); Data1=data1(:,[1:3,5]); [M,N]=size(Data1); current=ones(M,1)*[0 0.3,0.5,1]; frequency=[1,5:5:50]'*ones(1,N); amplitude1=ones(size(Data1)).*(0.02).*25.4./1000; gap1=ones(size(Data1)).*(0.1).*25.4./1000;
a=[ 198.7269 79.7653 -0.1376 23.8147 158.7006 0.6516];
Y1=(a(1).*current.^2+a(2).*current+a(3))./(2.*pi^2.*frequency.*amplitude1)./(a(5).*gap1+a(6))+a(4);
h=figure(1); for i=1:4 plot(frequency,Data1(:,i),linestr{i},'linewidth',linewidth); hold on plot(frequency,Y1(:,i),linestr{i+4},'linewidth',linewidth);
end LegednStr={'0.0Amps Test','0.0Amps Simulation ','0.3Amps Test','0.3Amps Simulation ','0.5Amps Test','0.5Amps Simulation ','1.0Amps Test','1.0Amps Simulation '}; titlestr=''; xLabelStr='test1'; yLabelStr='test2'; figName='test1';
setPlot(xLabelStr, yLabelStr,titlestr, LegednStr, figName);
%====
function setPlot(xLabelStr, yLabelStr,titlestr, LegednStr, figName) % % fig setting % % instructions of the interface£º % % xLabelStr£ºX_axis name str % % yLabelStr y_axis name str % % LegendStr£ºthe legend % % figName£º fig name box off;grid on; xlabel(xLabelStr, 'fontsize', 14, 'fontweight', 'bold'); ylabel(yLabelStr, 'fontsize', 14, 'fontweight', 'bold'); title(titlestr, 'fontsize', 14, 'fontweight', 'bold'); legend(LegednStr,0);legend boxoff; set(legend,'FontSize',14); set(gca,'LineWidth',1.5,'FontSize',14); Position = [0 0 793*2/3 596*2/3]; set(gcf,'position',Position) saveas(gcf, figName,'jpg'); end

1 comentario

Matt Fig
Matt Fig el 11 de Mzo. de 2011
You should use the "Code" format button to make that readable.

Iniciar sesión para comentar.

Respuestas (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 15 de Jun. de 2021

0 votos

With this syntax on legend settings, it is working ok.
close all; clear all;
...
...
titlestr=''; xLabelStr='test1'; yLabelStr='test2'; figName='test1';
setPlot(xLabelStr, yLabelStr,titlestr, LegednStr, figName);
...
%====
function setPlot(xLabelStr, yLabelStr,titlestr, LegednStr, figName)
% % fig setting % % instructions of the interface£º % %
box off;grid on;
xlabel(xLabelStr, 'fontsize', 14, 'fontweight', 'bold');
ylabel(yLabelStr, 'fontsize', 14, 'fontweight', 'bold');
title(titlestr, 'fontsize', 14, 'fontweight', 'bold');
legend(LegednStr);legend boxoff; set(legend,'FontSize',14);
set(gca,'LineWidth',1.5,'FontSize',14);
Position = [0 0 793*2/3 596*2/3]; set(gcf,'position',Position)
saveas(gcf, figName,'jpg');
end

Etiquetas

Preguntada:

el 11 de Mzo. de 2011

Respondida:

el 15 de Jun. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by