How to put in Multiple Inputs and Display Result in a Table

11 views (last 30 days)
Ok, so I have a problem where I have to write a program to find the force of a spring attached to a pulley with changing values of theta. I was able to write the program, so that it asks for the input theta and it calculates the weight/force. I now need to be able put in multiple inputs (10: 0-90 degrees in increments of 10 degrees). What is the process to do this, I am completely lost and have no idea how to do this. I have tried entering my input as a matrix, but I get an error. I also have to have the results be displayed in a table. Also lost on this subject. Thank you so much for any help.
Here is the code I have written thus far:
a=20
R=10;
k=5;
t=input('Enter Theta: ');
l=(sqrt((R*(sind(t)))^2+a^2));
x=(l-a);
S=k*x;
p=atand(a/(R*sind(t)));
F=S*cosd(p);
fprintf(' The weight to keep this at equilibrium is %.4f lbs \n',F);
  1 Comment
dpb
dpb on 10 Oct 2013
If it's to get input from user, probably easiest to ask for start, end and increment and then compute the vector from those. You could set some default values first to allow user to select them as shortcut.
doc inputdlg
may be of interest

Sign in to comment.

Accepted Answer

sixwwwwww
sixwwwwww on 10 Oct 2013
Dear Kyle, here is the code which works as you described:
a = 20;
R = 10;
k = 5;
t_start = input('Enter minimum value of theta: ');
t_end = input('Enter maximum value of theta: ');
t_increment = input('Enter increment value of theta: ');
t = t_start:t_increment:t_end;
l = (sqrt((R.*(sind(t))).^2+a^2));
x = (l-a);
S = k.*x;
p = atand(a./(R*sind(t)));
F = S.*cosd(p);
fprintf('Theta\tWeight[lbs]\n');
for i = 1:length(t)
fprintf('%d\t\t%.4f\n', t(i), F(i));
end
  2 Comments
Kyle
Kyle on 10 Oct 2013
Thank you, I didn't know how to input code as an interval.
sixwwwwww
sixwwwwww on 10 Oct 2013
By interval you mean the increment value from start to end? ow you mean the whole interval over which the values of theta vary?

Sign in to comment.

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices 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!