Plotting for a range of values
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Geoff Hayes
2020년 12월 10일
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);
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!