Using a for loop to test values in an equation

조회 수: 12 (최근 30일)
ALEXANDER MOUNTAIN
ALEXANDER MOUNTAIN 2021년 4월 26일
댓글: ALEXANDER MOUNTAIN 2021년 4월 26일
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에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by