for loop for the function
Informazioni
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Mostra commenti meno recenti
Hi all, here is my function
function [error] =stress5_function(Ke,n,Sult,u,t,S0,k,m)
pa=0.1013 ;
S3=5 ;
Ei=Ke.*pa.*(S3./pa).^n;
Rf=(S0+k.*exp(-(S3./m)))./(Sult+u.*exp(-(S3./t)));
% z=(£m1-£m3)
z=0:0.0001:5;
Et=Ei.*(1-(Rf.*z)./(S0+k.*exp(-(S3./m))));
Et(Et<0)=0;
x=(z./Et).*100;
A=xlsread('5MPa','A1:A32');
B=A';
C=xlsread('5MPa','B1:B32');
D=C';
startingIndex = find(x==0);
endingIndex = find(x>=16);
desiredX = x(startingIndex:endingIndex);
desiredZ = z(startingIndex:endingIndex);
A1 = trapz(desiredX,desiredZ);
A2= trapz(B,D);
error= ((A1-A2)./A1)*100;
end
there are 8 parameters in the function and the value of the parameters, I stored in an excel file
Ke=xlsread('parameters','A2:A9096');
n=xlsread('parameters','B2:B9096');
Sult=xlsread('parameters','C2:C9096');
u=xlsread('parameters','D2:D9096');
t=xlsread('parameters','E2:E9096');
S0=xlsread('parameters','F2:F9096');
k=xlsread('parameters','G2:G9096');
m=xlsread('parameters','H2:H9096');
pa=0.1013 ;
S3=5 ;
I want to create a for loop to run the function what should I write??
1 Commento
Risposte (1)
Your funtion accepts vectors as input. So there is no need to call it through a for loop. But if you really want to do this:
err = zeros(size(Ke));
for i = 1:numel(Ke)
err(i) = stress5_function(Ke(i),n(i),Sult(i),u(i),t(i),S0(i),k(i),m(i));
end
Better read the 5MPa file once only and provide the contents as inputs:
B = xlsread('5MPa','A1:A32').';
D = xlsread('5MPa','B1:B32').';
2 Commenti
Coleman
il 25 Feb 2016
Use the debugger to step throught your code line by line, until you find the reason for the unexpected values. Please note, that we cannot do this for you, because we do not have the input data and cannot guess, why you assume a vlue different from Inf.
Questa domanda è chiusa.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!