What's wrong in my simple for cycle code?
Show older comments
Hello everyone,
I load an input table as column vectors with the parameters I need to solve some equations (picture 1).

I implement a for cycle that it does not work properly. This is the code

clear; clc; close;
load('data')
k = [ID_STOP];
for i = 1:numel(k)
s = exp((GSI-100)/(9-3*D));
mb = mi.*exp((GSI-100)/(28-14*D));
a = 0.5 + ((exp(-GSI/15)-exp(-20/3))/6);
o3max = ocm.*0.72.*(ocm./w.*H).^-0.91 ;
o3n = o3max./oci;
friction_angle = asind((6.*a.*mb.*((s + mb.*o3n).^(a - 1)))/(2.*(1+a).*(2+a)+(6.*a.*mb.*((s + mb.*o3n).^(a - 1)))))
cohesion = 10^3*((oci.*(s.*(1+2.*a)+mb.*o3n.*(1-a))*((s + mb.*o3n).^(a - 1))) / ((1+a).*(2+a)*sqrt(1+(6.*a.*mb.*((s + mb.*o3n).^(a - 1))/(1+a).*(2+a)))))
results(i,:) =[friction_angle cohesion]
end
When I run the code (don't care about the %), "friction angle" is a vector of 110x110 NaN values. "cohesion" equation instead give me the error
"Error using /
Matrix dimensions must agree."
The results I would like to obtain are 110x1 vectors, one for friction angle results and the other for the cohesion results. I observe that the vector resulted from s, mb and a are 110x110. Why?
Thank everyone for the answers
Enrico
2 Comments
Geoff Hayes
on 27 Aug 2019
Enrico - can you post the code instead of a screen shot of the code? And perhaps include a small subset of the data too...
Enrico D'Addario
on 27 Aug 2019
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!