필터 지우기
필터 지우기

I want to store the output from my nested for loop in a matrix . How can it be done?

조회 수: 2 (최근 30일)
Bw=[150 155];
Rbwtobtf=[0.2,0.21];
Hf=[70 75];
Rdtoh=[0.85 0.86];
Tbf=[115 120];
Bbf= [250 260];
Mu=3400000000;
Fcu=50;
Rdtoh=[0.85 0.86];
Tbf=[115 120];
Bbf=[250 260];
for i=1:length(Bw)
for j=1:length(Rbwtobtf)
for k=1:length(Hf)
for l= 1:length(Rdtoh)
for m= 1:length(Tbf)
for n= 1: length(Bbf)
Btf=Bw(i)/Rbwtobtf(j);
syms x;
d=solve(Mu==Fcu*Btf*x^2*(0.157*Rbwtobtf(j)+(1-Rbwtobtf(j))*(Hf(k)/x)*(0.45-0.225*(Hf(k)/x))),x);
D=vpa(d);
De=D(1);
h= De/Rdtoh(l);
A1 = Btf*Hf(k);% Area of top flange
Hw = h-Hf(k)-Tbf(m);
A2 = Bw(i)*Hw; %Area of web
A3 = Bbf(n)*Tbf(m); %Area of bottom flange
A = A1+A2+A3; %Total area
disp (A);
n=n+1;
end
m=m+1;
end
l=l+1;
end
k=k+1;
end
j=j+1;
end
i=i+1;
end
I want to store values of A in a matrix. please help.

답변 (2개)

MathReallyWorks
MathReallyWorks 2017년 5월 26일
Hello Vinay,
Firstly, Make the code readable. It will be easy for us to solve your problem.
Anyways, your problem seems to be of multi dimensional array.
Use
A(n,m,l,k,j,i) = A1+A2+A3; %Total area
or
A(i,j,k,l,m,n) = A1+A2+A3; %Total area
in your code for storing the data in A.
Suggestion: Remove disp(A) which is just below this line.
  댓글 수: 1
vinay mhatre
vinay mhatre 2017년 5월 26일
it is not giving me a single matrix. I am getting multiple matrices while running the code. I want a single matrix with 64 rows in one column

댓글을 달려면 로그인하십시오.


Andrei Bobrov
Andrei Bobrov 2017년 5월 26일
편집: Andrei Bobrov 2017년 5월 26일
[EDIT]
Bw=[150 155];
Rbwtobtf=[0.2,0.21];
Hf=[70 75];
Rdtoh=[0.85 0.86];
Tbf=[115 120];
Bbf= [250 260];
Mu=3400000000;
Fcu=50;
[a,b,c0] = ndgrid(Hf,Rbwtobtf,Bw);
c = [c0(:),b(:),a(:)];
r0 = Fcu*c(:,1);
r = 9*r0.*c(:,3).*( 1./c(:,2) - 1);
p = [(157*r0)/1000, r/20, - Mu - r.*c(:,3)/40];
s = size(p,1);
dd = zeros(s,1);
for ii = 1:s
q = roots(p(ii,:));
dd(ii) = q(1);
end
[a,b,c0,n] = ndgrid(Bbf,Tbf,Rdtoh,1:s);
c = [c(n(:),:),c0(:),b(:),a(:)];
AA = c(:,1).*(c(:,3)./c(:,2) + dd(n(:))./c(:,4) - c(:,3) - c(:,5)) + c(:,6).*c(:,5);
  댓글 수: 3
vinay mhatre
vinay mhatre 2017년 5월 26일
the output of this program is giving me the desired matrix. but the values are wrong. The code which i have written gives me correct answer but the answer is not in the form of matrix. kindly help. thank you

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by