How come I can't plot this?

degree = 140:0.001:220;
thetad = 4;
f = atan(degree*(pi/180));
s = 90-f;
r = 0.1*(degree*(pi/180));
rd = diff(r);
Ar = -r*thetad^2;
Atheta = 2*rd*thetad;
Nc = (0.5*Ar)/cos(s);
Fc = (0.5*Atheta)+Nc*sin(s);
plot(degree,Ar,'black')
plot(degree,Atheta,'blue')
plot(degree,Nc,'yellow')
plot(degree,Fc,'green')
hold on;
grid on;

Answers (3)

Image Analyst
Image Analyst on 19 Nov 2018
Since diff(s) gives one less element than s, your array dimensions don't match when you try to add Atheta and sin(s).
The hold on call should be just after the first plot call, and diff produces a vector (here) that is one element shorter than its argument.
Try this:
degree = 140:0.001:220;
thetad = 4;
f = atan(degree*(pi/180));
s = 90-f;
r = 0.1*(degree*(pi/180));
rd = gradient(r);
Ar = -r*thetad^2;
Atheta = 2*rd*thetad;
Nc = (0.5*Ar)/cos(s);
Fc = (0.5*Atheta)+Nc*sin(s);
plot(degree,Ar,'black')
hold on
plot(degree,Atheta,'blue')
plot(degree,Nc,'yellow')
plot(degree,Fc,'green')
hold off
grid on
In addition to sir Image Analyst's explanation :
degree = 140:0.001:220;
thetad = 4;
f = atan(degree*(pi/180));
s = 90-f;
r = 0.1*(degree*(pi/180));
rd = diff(r);
Ar = -r*thetad^2;
Atheta = 2*rd*thetad;
Nc = (0.5*Ar)./cos(s);
Fc = (0.5.*Atheta)+Nc(1:numel(Atheta)).*sin(s(1:numel(Atheta)));
plot(degree(1:numel(Atheta)),Ar(1:numel(Atheta)),'black')
hold on;
plot(degree(1:numel(Atheta)),Atheta(1:numel(Atheta)),'blue')
plot(degree(1:numel(Atheta)),Nc(1:numel(Atheta)),'yellow')
plot(degree(1:numel(Atheta)),Fc(1:numel(Atheta)),'green')
grid on;

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Release

R2018b

Asked:

on 19 Nov 2018

Answered:

on 19 Nov 2018

Community Treasure Hunt

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

Start Hunting!