Using a for loop to test values in an equation

44 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Jan
Jan il 26 Apr 2021
Modificato: Jan il 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.
  1 Commento
ALEXANDER MOUNTAIN
ALEXANDER MOUNTAIN il 26 Apr 2021
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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by