フィルターのクリア

Legend ommit first plot title in multiple plots

1 回表示 (過去 30 日間)
Cesar Adolfo Cruz Vargaya
Cesar Adolfo Cruz Vargaya 2023 年 5 月 20 日
回答済み: Voss 2023 年 8 月 23 日
I am attempting to create a comparison plot between the original fuzzified data and a fitted version. However, the label for the first plot ('Data #1') is missing from the legend. I have tried adjusting the position of the 'hold on' command, but have been unable to resolve the issue."
clf, figure('Position',[1 1 600 300],'Units','pixels');
hold on
for i=1:length(uCenters)
fo = fitoptions( ...
'Method','NonlinearLeastSquares', ...
'StartPoint',[1 uCenters(i)], ...
'Lower',[0 -Inf]);
ft = fittype('gaussmf(x,[a,c])','options',fo);
f = fit(uSrt,uFCM(i,:)',ft);
H1 = plot(uSrt',uFCM(i,:),'--g');
H1.DisplayName = sprintf('Data #%d',i);
H2 = plot(f,'b');
H2.DisplayName = sprintf('Fuzzy #%d',i);
end
hold off, grid on, legend('Location','eastoutside','Box','off')
xlim([min(uSrt) max(uSrt)])
ylim([0 1.1])
xlabel('Voltaje (V)'), ylabel('Nivel de pertenencia')
title('Voltaje fuzzificado ajustado a curva gaussiana')
  1 件のコメント
dpb
dpb 2023 年 5 月 20 日
Without data to check against, it's hard to debug exactly, but I'd venture that the first data set are NaN.
Your code also overwirtes the plot and fit handles every pass through the loop so you can't inspect the results of each loop independently after the loop completes; only by setting breakpoint and using the debugger as is. It would be better to save an array of handles, then you could see each result more simply...

サインインしてコメントする。

採用された回答

Voss
Voss 2023 年 8 月 23 日
First, reproducing the problem using random data:
figure('Position',[1 1 600 300],'Units','pixels')
hold on
for i=1:5
x = rand(10,1);
y = rand(10,1);
fo = fitoptions( ...
'Method','NonlinearLeastSquares', ...
'StartPoint',[1 i], ...
'Lower',[0 -Inf]);
ft = fittype('gaussmf(x,[a,c])','options',fo);
f = fit(x,y,ft);
H1 = plot(x,y,'--g');
H1.DisplayName = sprintf('Data #%d',i);
H2 = plot(f,'b');
H2.DisplayName = sprintf('Fuzzy #%d',i);
end
hold off, grid on, legend('Location','eastoutside','Box','off')
xlabel('Voltaje (V)'), ylabel('Nivel de pertenencia')
title('Voltaje fuzzificado ajustado a curva gaussiana')
You can see that 'Data #1' is missing from the legend, as in your case. I'm not sure what causes that, but storing the line handles - as dpb suggested - and specifying them explicitly in the legend call seems to fix it:
figure('Position',[1 1 600 300],'Units','pixels')
hold on
for i=1:5
x = rand(10,1);
y = rand(10,1);
fo = fitoptions( ...
'Method','NonlinearLeastSquares', ...
'StartPoint',[1 i], ...
'Lower',[0 -Inf]);
ft = fittype('gaussmf(x,[a,c])','options',fo);
f = fit(x,y,ft);
H1(i) = plot(x,y,'--g');
H1(i).DisplayName = sprintf('Data #%d',i);
H2(i) = plot(f,'b');
H2(i).DisplayName = sprintf('Fuzzy #%d',i);
end
hold off, grid on, legend(reshape([H1; H2],[],1),'Location','eastoutside','Box','off')
xlabel('Voltaje (V)'), ylabel('Nivel de pertenencia')
title('Voltaje fuzzificado ajustado a curva gaussiana')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by