Using a for loop to test values in an equation
조회 수: 12 (최근 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
댓글 수: 0
채택된 답변
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!