绘制动画结果为空白图

时间:2018-02-20 00:13:32

标签: matlab animation plot graph

我已经编写了这段代码,但它不会绘制。我用0:.5:100运行它并在Matlab中得到一个空白图。这也是一个倾斜的平面摩擦问题。我需要在Matlab中创建一个动画,根据输入显示滑动块。

%Numerical Project Code 1

%mass ratio input
mratio = input('Enter the Mass Ratio(m/M): ');
%angle input
theta = input('Enter Angle in Degrees Between 0 and 90: ');
%static coeff input
mus = input('Enter Coefficient of Static Friction: ');
%kinetic coeff input
muk = input('Enter Coefficient of Kinetic Friction: ');

%constants
g = 9.81;

%interface formating
disp('--------------------------------------------');
disp('All Friction Forces are given in terms of the mass on the slope (M)');


%Loops
%NETUP

if mratio > sind(theta)
    %static only
    if mratio <= (sind(theta) + (mus*cosd(theta)))
        ff = g*(mratio - sind(theta));
        fprintf("Friction Force = %f M Newtons\n",ff);
        fprintf("The Direction of the Friction Force is down the slope and the block not moving.\n")




%kinetic only
else
    ff = muk * g * cosd(theta);
    fprintf("Friction Force = %f M Newtons\n",ff);
    fprintf("The Direction of the Friction Force is down the slope and the block is sliding up the slope.\n");


end



%NETDOWN

elseif mratio < sind(theta)
    %static only
    if sind(theta) <= (mratio + (mus*cosd(theta)))
        ff = g*(sind(theta) - mratio);
        fprintf("Friciton Force = %f M Newtons\n",ff);
        fprintf("The Direction of the Friction Force is up the slope and the block is not moving.\n")





%kinetic only
else 
    ff = muk * g * cosd(theta);
    fprintf("Friction Force = %f M Newtons\n",ff);
    fprintf("The Direction of the Friction Force is up the slope and the block is sliding down the slope.\n");


end


%NETZERO

else
    fprintf("Friction Force = 0 Newtons\n");



end
%graph
for i = 0:0.01:1


mratiog = i;

if mratiog  > sind(theta)

    if mratiog <= (sind(theta) + (mus*cosd(theta)))
        ffg = g*(mratiog - sind(theta));


   else 
        ffg =  muk * g * cosd(theta);


    end




elseif mratiog < sind(theta)

    if sind(theta) <= (mratiog + (mus*cosd(theta)))
        ffg = g*(sind(theta) - mratiog);

    else
        ffg = muk * g * cosd(theta);


   end



else
    ffg = 0;

end

  plot (ffg,mratio, 'r:')
end

1 个答案:

答案 0 :(得分:0)

除了Erik的评论之外,我还看到了另外两个问题:

  • 图表会在每次新迭代时更改其轴,因此您无法看到 动画得当。如果计算全部,它会更好 在绘制它们之前你的观点。然后您可以使用最小和最大数据 用于设置轴限制的尺寸。如果你不使用&#39;抓住&#39;你需要在每次迭代中设置限制。
  • 你需要使用&#39;暂停&#39;放慢速度 动画。否则你只看到最后一个数据点。

以下是“图表”的工作示例。部分:

%graph

i_arr = 0:0.01:1;
n = numel(i_arr);
ffg_mratio_arr = zeros(n, 2);

for i = 1:n
    mratiog = i_arr(i);

    if mratiog  > sind(theta)

        if mratiog <= (sind(theta) + (mus*cosd(theta)))
            ffg = g*(mratiog - sind(theta));
        else
            ffg =  muk * g * cosd(theta);
        end
    elseif mratiog < sind(theta)

        if sind(theta) <= (mratiog + (mus*cosd(theta)))
            ffg = g*(sind(theta) - mratiog);

        else
            ffg = muk * g * cosd(theta);
        end

    else
        ffg = 0;
    end

    ffg_mratio_arr(i,:) = [ffg mratio];
end

% calculating the axis limits
x_min = min(ffg_mratio_arr(:, 1))-1;
x_max = max(ffg_mratio_arr(:, 1))+1;

y_min = min(ffg_mratio_arr(:, 2))-1;
y_max = max(ffg_mratio_arr(:, 2))+1;

% animation
figure;

for i = 1:n
    plot (ffg_mratio_arr(i,1), ffg_mratio_arr(i,2), 'ro');

    xlim([x_min x_max]);
    ylim([y_min y_max]);

    pause(0.01);
end
相关问题