Using a for loop to test values in an equation
27 views (last 30 days)
Show older comments
ALEXANDER MOUNTAIN
on 26 Apr 2021
Commented: ALEXANDER MOUNTAIN
on 26 Apr 2021
I'm trying to use matlab to get values from an equation at different input values. I figured it would be easier on excel, but I couldn't get the equation to work for some reason. I'm analyzing a soil and trying to test equations for different angles of friction inputted from 0 to 90. It's been a while since I've taken a matlab class so I can't quite remember how to work a for loop. My goal is to have 90 values given to me that I could use to plug into excel and make a graph against my other axis dataset. Here's what i currently have. If another function works better for this that would also be okay. It also has to use degrees in the sin, cos and tan functions.
%i = 0; wasn't sure if I needed this
for i = 1:90
cVal = (350+(121*(5)-62.4*(4))*(cosd(i)^2)*(tand(24)))/(121*(5)*(sind(i))*(cosd(i)))
%above is the equation I need to test different values in.
%res = sprintf('%d\n', i); Wasn't sure if i needed this either
%it didn't work either way
end
0 Comments
Accepted Answer
Jan
on 26 Apr 2021
Edited: Jan
on 26 Apr 2021
Inserting too many parentheses looks confusing.
for i = 1:90
cVal = (350 + (121 * 5 - 62.4 * 4 ) * cosd(i)^2 * tand(24)) / (121*5*sind(i)*cosd(i));
fprintf('%g\t\n', cVal);
end
Now explain, what "did not work" exactly means. You can copy&paste the output to move it to Excel.
Or maybe:
v = 1:90;
cVal = (350 + (121 * 5 - 62.4 * 4 ) * cosd(v).^2 .* tand(24)) ./ ...
(121 * 5 * sind(v) .* cosd(i));
Str = sprintf('%g\t\n');
clipboard('copy', Str)
Now you can paste it into Excel directly.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!