If I follow this code I get the graph, but when I hit enter in the command window it says "Array index must be a positive integer or logical value" on line 45. I don't know what this means... .

1 次查看(过去 30 天)
Hf_fig = figure;
phi = 0: 15: 90;
heel = pi*phi/180;
B = 6.480;
T = [ 1.729 1.575 1.163 0.600 -0.012 -0.693 -1.354 ];
w = [ 0 1.122 1.979 2.595 2.945 2.874 2.539 ];
KB = [ 1.272 1.121 0.711 0.107 -0.625 -1.393 -2.108 ];
KM = [ 4.596 3.711 2.857 1.830 0.479 -0.869 -1.471 ];
set(Hf_fig, 'NumberTitle', 'off',...
'Name', 'B and M curves');
clf
x = -T.* sin(heel); y = T.*cos(heel) ; k = length(heel);
Bcenter(1,:) = [0 KB(1)];
M = zeros(2,k);
M(:,1) = [0 KB(1)];
f = max((B/0.8), (B^2/(12*T(1))+T(1)/2));
plot(Bcenter(:, 1), M(:, 2), 'b-')
axis([ -f/2 f/2 -T(1)/2 (f-T(1)/2) ])
axis('square')
P1 = [ 0.000; 0.50 ]; P2 = [ 0.240; 0.50 ];
P3 = [ 0.240; 0.58]; P4 = [ 1.100; 1.00 ]; P5 = [ 1.787; 1.25 ];
P6 = [ 2.460; 1.50 ]; P7 = [ 2.902; 1.75 ]; P8 = [ 3.100; 2.00 ];
P9 = [ 3.176; 2.25 ]; P10 = [ 3.200; 2.50 ]; P11 = [ 3.218; 2.75 ];
P12 = [ 3.230; 3.00 ]; P13 = [ 3.230; 3.36 ]; P14 = [ 2.099; 3.425 ];
P15 = [ 0.000; 3.489 ];
starb = [ P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P14 P15 ];
port = [ -starb(1, :); starb(2, :) ];
port = fliplr(port);
hold on
text(-B/1.8, T(1)+0.25, 'W_0')
text( B/1.8, T(1)+0.25, 'L_0')
text(-B/13, KB(1), 'B') , text(0, KM(1)+0.3, 'M')
xi = x(1) - B/1.5; yl = y(1); xr = x(1) + B/(1.8-1/10);
yr = y(1);
plot([ xi xr ], [ yl yr ])
plot(0, KB(1), 'r*')
plot(0, KM(1), 'ko')
plot([ 0 0 ], [ KB(1) KM(1) ], 'c-.')
pause
for I = 2:k
xi = x(1i) - B*cos(heel(l))/(1.5+l/1.7);
yl = y(1i) - B*sin(heel(l))/(1.5+l/1.7);
xr = x(1i) + B*cos(heel(l))/(1.8-l/10);
yr = y(1i) + B*sin(heel(l))/(1.8-l/10);
plot([ xi xr ], [ yl yr ])
if l ~= 1
string = [ num2str(phi(l)) '^o' ];
text(xi, yl, string)
text(xr, yr, string)
end
Bcenter(:, l) = rotate(heel(l))*[ w(l); KB(l) ];
plot(Bcenter(1, l), Bcenter(2, l), 'r*')
M(:, l) = rotate(heel(l))*[ w(l); KM(l) ];
plot(M(1, l), M(2, l), 'ko')
plot([ Bcenter(1, l), M(1, l) ], [ Bcenter(2, l), M(2, l) ],...
'k--')
pause(1)
end
pause
Bx = 0: Bcenter(1, k)/50: Bcenter(1, k); % interpolation axis
By = spline(Bcenter(1, :), Bcenter(2, :), Bx);
plot(Bx, By, 'm-')
Mx = 0: M(1, k)/50: M(1, k);
My = spline(M(1, :), M(2, :), Mx);
plot(Mx, My, 'y-') , text(-B/1.5, 1.4*KM(1),...
'The M-curve is the evolute of the B-curve')
hold off
function r = rotate(phi)
r = [ cos(phi) -sin(phi); sin(phi) cos(phi) ];
end
>> B_and_M_curves_demo
Array indices must be positive integers or logical values.
Error occurred : B_and_M_curves_demo (line 45)
xi = x(1i) - B*cos(heel(l))/(1.5+l/1.7);
It says that an error has occurred, but I don't know why
  2 个评论
James Tursa
James Tursa 2020-11-9
编辑:James Tursa 2020-11-9
Please copy & paste the complete error message, including the text pointing to the offending line and the offending line itself.
Voss
Voss 2020-11-23
What is the variable 'l' (that's a lower-case 'L') supposed to be? Maybe it should be 'I' (that's a capital 'i'), or vice versa.

请先登录,再进行评论。

回答(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