Looking at the graph, there should be 3 graphs in the legend, but why are there 5?

조회 수: 4 (최근 30일)
function [SteadyHeel] = SailCode(stability, KG, GM, downflood)
stability = [0 5 10 ...
85 900; 0 0.308 0.611...
3.249 3.216];
KG = 2.037;
GM = 1.5;
downflood = 55;
heel = stability(1,:);
k = stability(2,:);
GZ = k - KG * sind(heel);
heeli = 0:2.5:heel(end);
if nargin < 4
SteadyHeel = stability, KG, GM, downflood;
end
GZi = spline(heel,GZ,heeli);
GZf = spline(heel,GZ,downflood);
WLO = GZf/cosd(downflood)^1.3; gust = WLO*cosd(heeli).^1.3;
steady = gust/2;
plot(heeli,GZi, 'k-', heeli,gust,'r--',heeli, steady,'g--');
title('Sail-vessel stability according to UK Maritime and Coastguard Agency');
xlabel('Heel angle,deg')
ylabel('Lever arms, m')
legend('GZ', 'Gust wind', 'Steady wind');
axis([0,90,0,2.5])
hold on
plot([ 0 180/pi],[0 GM],'k-');
text(1.5,1.25, ('Angle of steady heel = 35.7719 deg'))
text(heeli(2), 1.02*gust(2), 'WLO');
plot([ downflood downflood ], [ 0 GZf ], 'k-')
text(1.01*downflood, 0.05*GZf, 'Downflooding angle');
hold off
end

채택된 답변

Mathieu NOE
Mathieu NOE 2020년 10월 28일
hi
i guess the legend will be messed up with hold on / hold off afterwards
i put it at the end and I could get the expected 3 labels in the legend
BTW I was surprised to have a warning : gust and
I couldn't figure the reason for getting a complex output from a real valued vector , so I finally made a work around function (for what it's worth)
% gust = WLO*cosd(heeli).^1.3; % this generates a complex output (??)
gust = mypower(WLO*cosd(heeli),1.3); % this generates a real output (as expected)
steady = gust/2;
plot(heeli,GZi, 'k-', heeli,gust,'r--',heeli, steady,'g--');
title('Sail-vessel stability according to UK Maritime and Coastguard Agency');
xlabel('Heel angle,deg')
ylabel('Lever arms, m')
% legend('GZ', 'Gust wind', 'Steady wind');
axis([0,90,0,2.5])
hold on
plot([ 0 180/pi],[0 GM],'k-');
text(1.5,1.25, ('Angle of steady heel = 35.7719 deg'))
text(heeli(2), 1.02*gust(2), 'WLO');
plot([ downflood downflood ], [ 0 GZf ], 'k-')
text(1.01*downflood, 0.05*GZf, 'Downflooding angle');
hold off
legend('GZ', 'Gust wind', 'Steady wind');
function [y] = mypower(x,a)
ss = sign(x);
y_log = a.*log10(abs(x));
y = ss.*10.^(y_log);
end
  댓글 수: 1
Mathieu NOE
Mathieu NOE 2020년 10월 28일
sorry
there was a missing part in my sentence :
BTW I was surprised to have a warning : "gust" and "steady" are both complex numbers , which I didn't expect. Reasons ???

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by