Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
for loop for the function
조회 수: 7 (최근 30일)
이전 댓글 표시
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
Stephen23
2016년 2월 24일
Do NOT call any variable or function error, because then you stop the very important inbuilt function error from working properly. For the same reason you should never name any variable or function size, length, cell, table, i, j, etc.
답변 (1개)
Jan
2016년 2월 24일
편집: Jan
2016년 2월 25일
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
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!