Clear Filters
Clear Filters

Why is my Plot Blank?

1 view (last 30 days)
Anna Bernbaum
Anna Bernbaum on 24 Oct 2016
Answered: Thorsten on 25 Oct 2016
Hi, my code returns a blank plot and I dont know why
Code:
beta1 = 0.1
theta = [0: 0.1: 90];
function dyds = motorbike(betas)
for theta = [0: 0.1: 90]
a = 3/(8*betas);
b = sqrt(8*(sind(theta)).^2 + 1);
c = sind(theta)*(cosd(theta)).^3;
dyds = a*(b/c);
end
%dyds = (3/(8*betas))*sqrt((8*sin(theta).^2)+1)/sin(theta)*cos(theta).^3;
end
figure
plot(theta, motorbike(beta1))

Answers (2)

Roger Stafford
Roger Stafford on 24 Oct 2016
You need to index dyds so that it contains a value for each value of ‘theta’:
dyds = zeros(1,length(theta));
for k = 1:length(theta)
...
b = sqrt(8*(sind(theta(k))).^2 + 1);
c = sind(theta(k))*(cosd(theta(k))).^3;
dyds(k) = a*(b/c);
end

Thorsten
Thorsten on 25 Oct 2016
You don't need the for loop, you can work on the vector beta. You just have to replace * and / with .* and ./ (you already use .^)
betas = 0.1
theta = [0: 0.1: 90];
a = 3/(8*betas);
b = sqrt(8*(sind(theta)).^2 + 1);
c = sind(theta).*(cosd(theta)).^3;
dyds = a.*(b./c);

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!