Using a for loop to test values in an equation

33 次查看(过去 30 天)
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

采纳的回答

Jan
Jan 2021-4-26
编辑:Jan 2021-4-26
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.
  1 个评论
ALEXANDER MOUNTAIN
ALEXANDER MOUNTAIN 2021-4-26
Yes that's exactly what I was looking for, thank you. "Did not work" was just referencing how the equation did not return the values I was hoping for in the actual excel document but these values from matlab gave the shape I was looking for in this specific soil.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by