Plot problem though there are data numbers

1 view (last 30 days)
Hello,
I made code in Matlab to produce a plot like in this picture. Although there are numbers but the graph does not work.
Thanks for the helpers and Happy New Year :)
K_t=750;
K_r=250;
b=5;
f_z=0.1;
time=0:0.008 ;
for i = 1: length(time)
t2 = mod(time(i), 0.002);
if (t2 >= 0.00134 & t2 <= 0.002)
F_x(i)=0;
F_y(i)=0;
F(i)=0;
else
st2 = sind(t2);
ct2 = cosd(t2);
h_cut = f_z * st2;
F_r=K_r*b*h_cut;
F_t=K_t*b*h_cut;
F_x(i) = -F_t .* ct2 + F_r .* st2;
F_y(i) = F_t .* st2 + F_r .* ct2;
F(i)=sqrt((F_x(i)).^2+(F_y(i)).^2);
end
end
plot(time,F_x,'--r',time,F_y,'--b',time,F,'k' )
legend('F_x' ,'F_y','F')
title('The components of the forces as a function of the angle of chip in the Up milling');
xlabel('Time [Seconds]');
ylabel('Force [N]');

Accepted Answer

Voss
Voss on 30 Dec 2021
The reason the graph appears empty is because time=0:0.008 is a vector with only one element (0). What you need to do is specify a step-size, like time=0:0.00001:0.008, which is a vector that starts at 0 and goes to 0.008 in steps of 0.00001. (If you don't specify a step-size, the default step-size of 1 is used, which is not useful when the maximum value is 0.008.) Here's what you get with that time vector:
K_t=750;
K_r=250;
b=5;
f_z=0.1;
% time=0:0.008 ;
time=0:0.00001:0.008 ;
for i = 1: length(time)
t2 = mod(time(i), 0.002);
if (t2 >= 0.00134 & t2 <= 0.002)
F_x(i)=0;
F_y(i)=0;
F(i)=0;
else
st2 = sind(t2);
ct2 = cosd(t2);
h_cut = f_z * st2;
F_r=K_r*b*h_cut;
F_t=K_t*b*h_cut;
F_x(i) = -F_t .* ct2 + F_r .* st2;
F_y(i) = F_t .* st2 + F_r .* ct2;
F(i)=sqrt((F_x(i)).^2+(F_y(i)).^2);
end
end
plot(time,F_x,'--r',time,F_y,'--b',time,F,'k' )
legend('F_x' ,'F_y','F')
title('The components of the forces as a function of the angle of chip in the Up milling');
xlabel('Time [Seconds]');
ylabel('Force [N]');

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!