Plotting for a range of values

2 Ansichten (letzte 30 Tage)
Verdan Chick
Verdan Chick am 10 Dez. 2020
Beantwortet: Geoff Hayes am 10 Dez. 2020
mA = 10;
muA = 0.3;
muB = 0.1;
g = 9.81;
theta = 30;
NA = mA*g*cosd(theta);
NB = mB*g*cosd(theta);
for mB = [1:1:20]
a = ((mA)*(g)*(sind(theta)) - (muA)*(NA) + (mB)*(g)*(sind(theta)) - (muB)*(NB)) / (mA + mB)
end
plot(mB,a)
The graph is not showing a curve and the x-axis values are incorrect. Quite new to matlab, but I have used a for loop in order to gain multiple values for 'a' when mB ranges from 1-20 in increments of 1. Could anyone help?
Thank you

Antworten (1)

Geoff Hayes
Geoff Hayes am 10 Dez. 2020
Verdan - in your code, the mB and a are scalars whereas you want them to be arrays (for when you plot outside of the loop). Try doing
xData = 1:1:20;
a = size(xData);
for mB = xData
NB = mB*g*cosd(theta); % I moved this here since it depends upon mB
a(mB) = ((mA)*(g)*(sind(theta)) - (muA)*(NA) + (mB)*(g)*(sind(theta)) - (muB)*(NB)) / (mA + mB);
end
plot(xData,a);

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by