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

1 次查看(过去 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