how can you plot a matrix row vs row using a for loop
3 次查看(过去 30 天)
显示 更早的评论
We were given 5 springs and had to put 3 different masses on each spring and then measure the displacement for each spring for each mass (3 masses & 3 displacements per spring).
% Masses for each Spring [g]: % 3 masses per spring
S1_M=[10 20 30];
S2_M=[20 30 50];
S3_M=[50 100 150];
S4_M=[100 200 300];
S5_M=[100 200 300];
% Displacement for each Spring [in]: % Displacements for each mass
S1_D=[1.35 2.95 4.45];
S2_D=[1.05 1.65 2.85];
S3_D=[1.1 2.55 3.9];
S4_D=[1.75 4.1 6.3];
S5_D=[1.25 2.9 4.45];
% Convert displacement from [in] to [m]:
S1_D=S1_D*0.0254;
S2_D=S2_D*0.0254;
S3_D=S3_D*0.0254;
S4_D=S4_D*0.0254;
S5_D=S5_D*0.0254;
% Convert mass[g] to force[N]:
S1_M=S1_M*0.0098;
S2_M=S2_M*0.0098;
S3_M=S3_M*0.0098;
S4_M=S4_M*0.0098;
S5_M=S5_M*0.0098;
% Create a single matrix for all 5 springs:
Disp=[S1_M;S1_D;S2_M;S2_D;S3_M;S3_D;S4_M;S4_D;S5_M;S5_D];
I know im right up until this point.
Then it says: in a function, use polyfit to determine the stiffness of each individual spring. Use a for loop within the function to accomplish these caculations. There are 5 springs and we are supposed to plot the force versus the displacement for each individual spring in a new figure. Below is how I started it, am I even doing this right?
? - means I don't know what variable to put there
% Create a for loop using polyfit to calculate the spring constants:
function[?]=?
[r,c]=size(Disp)
for i=1:1:r
for j=1:1:c %im missing the ployfit part
plot(Disp(?),Disp(?),'bo') in the for loop
end
end
6 个评论
Daniel Shub
2013-3-8
http://www.mathworks.com/matlabcentral/answers/29922-why-your-question-is-not-urgent-or-an-emergency
You are essentially asking I to do your homework for you. That is not appreciated. Edit the question to show what you have tried, otherwise I will keep closing the question.
回答(1 个)
Image Analyst
2013-3-8
编辑:Image Analyst
2013-3-8
Assuming you have one mass at a time hanging vertically down, where the other end of the spring is attached to the ceiling, you can say force = k*distance = mass*acceleration = mass*g. So k = force / distance. You have the force and you have the distance so you just need to make up the 3 k's I would guess. Though I don't know why you need polyfit instead of just averaging the 3 k's. Then you do that for each of the 5 springs.
13 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!