Perform for loop and carry out calculation separately

조회 수: 1 (최근 30일)
Davide Bertoldi
Davide Bertoldi 2020년 11월 16일
편집: Shadaab Siddiqie 2020년 11월 20일
Dear community,
I´m once again asking for your help!
As visible in the code below, I´m trying to perform a for loop in steps of 1:1:823´543 (which corresponds to the length of vector a_1_7a. What I ultimately want to achieve, is that these c- and D-factors are calculated for every single value of the given range (which means that the related value is to be extracted from a previously defined vector, in this case depth_7a_p). After calculating 823´543 values for c and D a related number (823543) of matrices V_7a_p and vectors S_7a_p shall be created. Finally, the same amount of gamma factor vector is to be calculated and extracted from the for loop.
For some reason I don´t understand, this doesn´t work. Hopefully you´re able to help me.
Greetings
David
for n=1:1:length(a_1_7a)
c_1_2=width*G./depth_7a_p(n,1).*10^3;
c_2_3=width*G./depth_7a_p(n,2).*10^3;
c_3_4=width*G./depth_7a_p(n,3).*10^3;
c_4_5=width*G./depth_7a_p(n,4).*10^3;
D_1=pi^2*E_0*width.*depth_7a_p(n,1)./(span).*10^-3;
D_2=pi^2*E_0*width.*depth_7a_p(n,2)./(span).*10^-3;
D_3=pi^2*E_0*width.*depth_7a_p(n,3)./(span).*10^-3;
D_4=pi^2*E_0*width.*depth_7a_p(n,4)./(span).*10^-3;
D_5=pi^2*E_0*width.*depth_7a_p(n,5)./(span).*10^-3;
a_3_7a(n)=0;
V_7a_p=[(c_1_2+D_1)*a_1_7a(n) -c_1_2*a_2_7a(n) 0 0 0; -c_1_2*a_1_7a(n) (c_1_2+c_2_3+D_2)*a_2_7a(n) -c_2_3*a_3_7a(n) 0 0; 0 -c_2_3*a_2_7a(n) (c_2_3+c_3_4+D_3)*a_3_7a(n) -c_3_4*a_4_7a(n) 0; 0 0 -c_3_4*a_3_7a(n) (c_3_4+c_4_5+D_4)*a_4_7a(n) -c_4_5*a_5_7a(n); 0 0 0 -c_4_5*a_4_7a(n) (c_4_5+D_5)*a_5_7a(n)];
S_7a_p=[-c_1_2*(a_2_7a(n)-a_1_7a(n));-c_2_3*(a_3_7a(n)-a_2_7a(n))+c_1_2*(a_2_7a(n)-a_1_7a(n));-c_3_4*(a_4_7a(n)-a_3_7a(n))+c_2_3*(a_3_7a(n)-a_2_7a(n));-c_4_5*(a_5_7a(n)-a_4_7a(n))+c_3_4*(a_4_7a(n)-a_3_7a(n));c_4_5*(a_5_7a(n)-a_4_7a(n))];
gamma_7a_1=(V_7a_p).^-1.*S_7a_p;
end
  댓글 수: 2
Rik
Rik 2020년 11월 16일
You are overwriting most variables in your loop, instead of indexing them.
The variable names look like you are using many numbered variables, which is generally a bad idea. You might be tempted to try to generate the variable names at runtime, instead of using indexing. You are also hiding a lot of information because you don't use descriptive variable names or comments.
Why don't you first try to get your code working and optimize it before you throw almost a million iterations at it. Can you try to find a way to vectorize your code?
Davide Bertoldi
Davide Bertoldi 2020년 11월 18일
Hello Rik,
firstly thanks for your answer which made to apply some modifications and comments to my code, which I now am showing as a whole. Obviously, If you have some concrete ideas on how to rationalize and improve it, I would be really thankful.
Still, even tough the code is working rather fast (25 sec), but this i set to change as soon as the calculation is repeated for more spans (see row 60-61). How would a preallocation look like? Could you give me some hints? I could not yet figure it out, because I´m a newbie to programming...
My 2nd question is about the loop. Even though I set the number of loops to a certain value, the extracted matrix produces some 600 ca. more. The way to extract vectors from a loop is obtained from: https://de.mathworks.com/videos/how-to-store-a-series-of-vectors-from-a-for-loop-97220.html.
I`m looking forward to your answer and help
%Strength values for CLT
G=0.69; %kN/mm²
E_0=11;
E_0_1_7=ones(1,7).*11;%kN/mm²
E_90=0.37; %kN/mm²
%Number of lamellas [-]
lam=3:2:7;
%Span length [m]
span=3.0:0.5:6.0;
%Analysed width [m]
width=1;
%Depth outer lamella parallel to span [mm]
lam_o_p=20:5:50;
%Depth inner lamella parallel to span [mm]
lam_i_p=20:5:50;
%Depth inner lamella cross to span [mm]
lam_i_c=20:5:50;
%Depth vector of CLT panels [mm] total number of possible combinations
depth_7a=combvec(lam_o_p,lam_i_p,lam_i_c,lam_i_p,lam_i_c,lam_i_p,lam_o_p)'; %2*lam_o_p+lam_i_c+lam_i_p+lam_i_c+2*lam_o_p
%Depth vector of CLT panels [mm] parallel to span [mm]
depth_7a_p=depth_7a(:,[1 2 4 6 7]);
depth_7a_p_1=depth_7a_p(:,1);
depth_7a_p_2=depth_7a_p(:,2);
depth_7a_p_3=depth_7a_p(:,3);
depth_7a_p_4=depth_7a_p(:,4);
depth_7a_p_5=depth_7a_p(:,5);
%Depth vector of CLT panels [mm] cross to span [mm]
depth_7a_c=depth_7a(:,[3 5]);
%Total depth of CLT panels [mm]
depth_7a_tot=sum(depth_7a,2); %sum(depth_x,2) where 2 stands for row-wise addition
%Determination of Ares CLT panel parallel to span [m²]
A_CLT_7a_p=10^-3.*depth_7a_p.*width;
%Determination of Ares CLT panel cross to span [m²]
A_CLT_7a_c=10^-3.*depth_7a_c.*width;
%Calculation position center of gravity for CLT_7a,CLT_7b [mm]
zs_CLT_7a=(A_CLT_7a_p(:,1).*(0.5.*depth_7a_p(:,1))+A_CLT_7a_p(:,2).*(depth_7a_p(:,1)+0.5.*depth_7a_p(:,2))+A_CLT_7a_c(:,1).*(depth_7a_p(:,1)+depth_7a_p(:,2)+0.5.*depth_7a_c(:,1))+A_CLT_7a_p(:,3).*(depth_7a_p(:,1)+depth_7a_p(:,2)+depth_7a_c(:,1)+0.5.*depth_7a_p(:,3))+A_CLT_7a_c(:,2).*(depth_7a_p(:,1)+depth_7a_p(:,2)+depth_7a_c(:,1)+depth_7a_p(:,3)+0.5.*depth_7a_c(:,2))+A_CLT_7a_p(:,4).*(depth_7a_p(:,1)+depth_7a_p(:,2)+depth_7a_c(:,1)+depth_7a_p(:,3)+depth_7a_c(:,2)+0.5.*(depth_7a_p(:,4)))+A_CLT_7a_p(:,5).*(depth_7a_p(:,1)+depth_7a_p(:,2)+depth_7a_c(:,1)+depth_7a_p(:,3)+depth_7a_c(:,2)+depth_7a_p(:,4)+0.5.*(depth_7a_p(:,5))))./(A_CLT_7a_p(:,1)+A_CLT_7a_p(:,2)+A_CLT_7a_p(:,3)+A_CLT_7a_p(:,4)+A_CLT_7a_p(:,5)+A_CLT_7a_c(:,1)+A_CLT_7a_c(:,2)); %[mm]
%Distances between center of gravity and lamellas [mm]
a_1_7a=zs_CLT_7a-(0.5.*depth_7a_p(:,1));
a_2_7a=zs_CLT_7a-(depth_7a_p(:,1)+0.5.*depth_7a_p(:,2));
a_2_3_7a=zs_CLT_7a-(depth_7a_p(:,1)+depth_7a_p(:,2)+0.5.*depth_7a_c(:,1));%cross layer in between
a_3_7a=zeros(823543,1);
a_3_4_7a=-zs_CLT_7a+(depth_7a_p(:,4)+depth_7a_p(:,5)+0.5.*depth_7a_c(:,2));%cross layer in between
a_4_7a=-zs_CLT_7a+(0.5.*depth_7a_p(:,4)+depth_7a_p(:,5));
a_5_7a=-zs_CLT_7a+(depth_7a_p(:,5));
%first round of calculation for span_1=3.0m
span_1=span(1);
%Calculation of c-factors for matrix [kN/mm]
c_1_2=width*G./depth_7a_p_1.*10^3;
c_2_3=width*G./depth_7a_p_2.*10^3;
c_3_4=width*G./depth_7a_p_3.*10^3;
c_4_5=width*G./depth_7a_p_4.*10^3;
%Calculation of D-factors for matrix [kN/mm]
D_1=pi^2*E_0*width.*depth_7a_p_1./(span_1).*10^-3;
D_2=pi^2*E_0*width.*depth_7a_p_2./(span_1).*10^-3;
D_3=pi^2*E_0*width.*depth_7a_p_3./(span_1).*10^-3;
D_4=pi^2*E_0*width.*depth_7a_p_4./(span_1).*10^-3;
D_5=pi^2*E_0*width.*depth_7a_p_5./(span_1).*10^-3;
n=1:1:823543;
%Matrix [5x5] where every element is a (823543x1) vector
V_7a_p=[(c_1_2(n)+D_1(n)).*a_1_7a(n) -c_1_2(n).*a_2_7a(n) zeros(823543,1) zeros(823543,1) zeros(823543,1); -c_1_2(n).*a_1_7a(n) (c_1_2(n)+c_2_3(n)+D_2(n)).*a_2_7a(n) -c_2_3(n).*a_3_7a(n) zeros(823543,1) zeros(823543,1); zeros(823543,1) -c_2_3(n).*a_2_7a(n) (c_2_3(n)+c_3_4(n)+D_3(n)).*a_3_7a(n) -c_3_4(n).*a_4_7a(n) zeros(823543,1); zeros(823543,1) zeros(823543,1) -c_3_4(n).*a_3_7a(n) (c_3_4(n)+c_4_5(n)+D_4(n)).*a_4_7a(n) -c_4_5(n).*a_5_7a(n); zeros(823543,1) zeros(823543,1) zeros(823543,1) -c_4_5(n).*a_4_7a(n) (c_4_5(n)+D_5(n)).*a_5_7a(n)];
%S-Vector [(5x1] where every element is a (823543x1) vector
S_7a_p=[-c_1_2(n).*(a_2_7a(n)-a_1_7a(n));-c_2_3(n).*(a_3_7a(n)-a_2_7a(n))+c_1_2(n).*(a_2_7a(n)-a_1_7a(n));-c_3_4(n).*(a_4_7a(n)-a_3_7a(n))+c_2_3(n).*(a_3_7a(n)-a_2_7a(n));-c_4_5(n).*(a_5_7a(n)-a_4_7a(n))+c_3_4(n).*(a_4_7a(n)-a_3_7a(n));c_4_5(n).*(a_5_7a(n)-a_4_7a(n))];
%Start of for loop with the idea to calculate 823543 5x5 matrices with related number of s-vectors
for n=1:1:823543
V_7a_p_n=V_7a_p([n,823543+n,1647086+n,2470629+n,3294172+n],:);
S_7a_p_n=S_7a_p([n,823543+n,1647086+n,2470629+n,3294172+n],:);
gamma_7a_n=pinv(V_7a_p_n)*S_7a_p_n;
mat_gamma_7a(n,:)=gamma_7a_n;
end
%Extracting wanted results for further calculation from the 1st to the 823543th row. For some reason the
%code gives 824516 rows.
mat_gamma_7a_p=mat_gamma_7a(1:1:823543,:);

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

답변 (1개)

Shadaab Siddiqie
Shadaab Siddiqie 2020년 11월 19일
From my understanding you want to accelerate your code. Please vectorize your code. This reference might help you.
  댓글 수: 2
Davide Bertoldi
Davide Bertoldi 2020년 11월 19일
Hello, so I tried to vectorize the code. Below you can see the whole vectorized code instead of the for loop. What I couldn´t achieve until now is that the matrix V_7a_p and vector S_7a_p are calculated separately for every value of n_1. I need to perform such task because I need separated values for gamma_7a_n_span_1. Currently I cannot think of any other way than a for loop as shown above. How would you handle it?
%Strength values for CLT
G=0.69; %kN/mm²
E_0=11;
E_0_1_7=ones(1,7).*11;%kN/mm²
E_90=0.37; %kN/mm²
%Number of lamellas [-]
lam=3:2:7;
%Span length [m]
span=3.0:0.5:6.0;
%Analysed width [m]
width=1;
%Depth outer lamella parallel to span [mm]
lam_o_p=20:5:50;
%Depth inner lamella parallel to span [mm]
lam_i_p=20:5:50;
%Depth inner lamella cross to span [mm]
lam_i_c=20:5:50;
%Depth vector of CLT panels [mm] total number of possible combinations
depth_7a=combvec(lam_o_p,lam_i_p,lam_i_c,lam_i_p,lam_i_c,lam_i_p,lam_o_p)'; %2*lam_o_p+lam_i_c+lam_i_p+lam_i_c+2*lam_o_p
%Depth vector of CLT panels [mm] parallel to span [mm]
depth_7a_p=depth_7a(:,[1 2 4 6 7]);
depth_7a_p_1=depth_7a_p(:,1);
depth_7a_p_2=depth_7a_p(:,2);
depth_7a_p_3=depth_7a_p(:,3);
depth_7a_p_4=depth_7a_p(:,4);
depth_7a_p_5=depth_7a_p(:,5);
%Depth vector of CLT panels [mm] cross to span [mm]
depth_7a_c=depth_7a(:,[3 5]);
%Total depth of CLT panels [mm]
depth_7a_tot=sum(depth_7a,2); %sum(depth_x,2) where 2 stands for row-wise addition
%Determination of Ares CLT panel parallel to span [m²]
A_CLT_7a_p=10^-3.*depth_7a_p.*width;
%Determination of Ares CLT panel cross to span [m²]
A_CLT_7a_c=10^-3.*depth_7a_c.*width;
%Calculation position center of gravity for CLT_7a,CLT_7b [mm]
zs_CLT_7a=(A_CLT_7a_p(:,1).*(0.5.*depth_7a_p(:,1))+A_CLT_7a_p(:,2).*(depth_7a_p(:,1)+0.5.*depth_7a_p(:,2))+A_CLT_7a_c(:,1).*(depth_7a_p(:,1)+depth_7a_p(:,2)+0.5.*depth_7a_c(:,1))+A_CLT_7a_p(:,3).*(depth_7a_p(:,1)+depth_7a_p(:,2)+depth_7a_c(:,1)+0.5.*depth_7a_p(:,3))+A_CLT_7a_c(:,2).*(depth_7a_p(:,1)+depth_7a_p(:,2)+depth_7a_c(:,1)+depth_7a_p(:,3)+0.5.*depth_7a_c(:,2))+A_CLT_7a_p(:,4).*(depth_7a_p(:,1)+depth_7a_p(:,2)+depth_7a_c(:,1)+depth_7a_p(:,3)+depth_7a_c(:,2)+0.5.*(depth_7a_p(:,4)))+A_CLT_7a_p(:,5).*(depth_7a_p(:,1)+depth_7a_p(:,2)+depth_7a_c(:,1)+depth_7a_p(:,3)+depth_7a_c(:,2)+depth_7a_p(:,4)+0.5.*(depth_7a_p(:,5))))./(A_CLT_7a_p(:,1)+A_CLT_7a_p(:,2)+A_CLT_7a_p(:,3)+A_CLT_7a_p(:,4)+A_CLT_7a_p(:,5)+A_CLT_7a_c(:,1)+A_CLT_7a_c(:,2)); %[mm]
%Distances between center of gravity and lamellas [mm]
a_1_7a=zs_CLT_7a-(0.5.*depth_7a_p(:,1));
a_2_7a=zs_CLT_7a-(depth_7a_p(:,1)+0.5.*depth_7a_p(:,2));
a_2_3_7a=zs_CLT_7a-(depth_7a_p(:,1)+depth_7a_p(:,2)+0.5.*depth_7a_c(:,1));%cross layer in between
a_3_7a=zeros(823543,1);
a_3_4_7a=-zs_CLT_7a+(depth_7a_p(:,4)+depth_7a_p(:,5)+0.5.*depth_7a_c(:,2));%cross layer in between
a_4_7a=-zs_CLT_7a+(0.5.*depth_7a_p(:,4)+depth_7a_p(:,5));
a_5_7a=-zs_CLT_7a+(depth_7a_p(:,5));
%Calculation of c-factors for matrix [kN/mm]
c_1_2=width*G./depth_7a_p_1.*10^3;
c_2_3=width*G./depth_7a_p_2.*10^3;
c_3_4=width*G./depth_7a_p_3.*10^3;
c_4_5=width*G./depth_7a_p_4.*10^3;
%Calculation of D-factors for matrix [kN/mm]
D_1=pi^2*E_0*width.*depth_7a_p_1./(span).*10^-3;
D_2=pi^2*E_0*width.*depth_7a_p_2./(span).*10^-3;
D_3=pi^2*E_0*width.*depth_7a_p_3./(span).*10^-3;
D_4=pi^2*E_0*width.*depth_7a_p_4./(span).*10^-3;
D_5=pi^2*E_0*width.*depth_7a_p_5./(span).*10^-3;
n=[(1:1:length(a_1_7a)),1]';
length_n=length(n);
%Matrix [5x5] where every element is a (823543x1) vector for span_1 to span_7
V_7a_p_span_1=[(c_1_2+D_1(1)).*a_1_7a -c_1_2.*a_2_7a zeros(823543,1) zeros(823543,1) zeros(823543,1); -c_1_2.*a_1_7a (c_1_2+c_2_3+D_2(1)).*a_2_7a -c_2_3.*a_3_7a zeros(823543,1) zeros(823543,1); zeros(823543,1) -c_2_3.*a_2_7a (c_2_3+c_3_4+D_3(1)).*a_3_7a -c_3_4.*a_4_7a zeros(823543,1); zeros(823543,1) zeros(823543,1) -c_3_4.*a_3_7a (c_3_4+c_4_5+D_4(1)).*a_4_7a -c_4_5.*a_5_7a; zeros(823543,1) zeros(823543,1) zeros(823543,1) -c_4_5.*a_4_7a (c_4_5+D_5(1)).*a_5_7a];
V_7a_p_span_2=[(c_1_2+D_1(2)).*a_1_7a -c_1_2.*a_2_7a zeros(823543,1) zeros(823543,1) zeros(823543,1); -c_1_2.*a_1_7a (c_1_2+c_2_3+D_2(2)).*a_2_7a -c_2_3.*a_3_7a zeros(823543,1) zeros(823543,1); zeros(823543,1) -c_2_3.*a_2_7a (c_2_3+c_3_4+D_3(2)).*a_3_7a -c_3_4.*a_4_7a zeros(823543,1); zeros(823543,1) zeros(823543,1) -c_3_4.*a_3_7a (c_3_4+c_4_5+D_4(2)).*a_4_7a -c_4_5.*a_5_7a; zeros(823543,1) zeros(823543,1) zeros(823543,1) -c_4_5.*a_4_7a (c_4_5+D_5(2)).*a_5_7a];
V_7a_p_span_3=[(c_1_2+D_1(3)).*a_1_7a -c_1_2.*a_2_7a zeros(823543,1) zeros(823543,1) zeros(823543,1); -c_1_2.*a_1_7a (c_1_2+c_2_3+D_2(3)).*a_2_7a -c_2_3.*a_3_7a zeros(823543,1) zeros(823543,1); zeros(823543,1) -c_2_3.*a_2_7a (c_2_3+c_3_4+D_3(3)).*a_3_7a -c_3_4.*a_4_7a zeros(823543,1); zeros(823543,1) zeros(823543,1) -c_3_4.*a_3_7a (c_3_4+c_4_5+D_4(3)).*a_4_7a -c_4_5.*a_5_7a; zeros(823543,1) zeros(823543,1) zeros(823543,1) -c_4_5.*a_4_7a (c_4_5+D_5(3)).*a_5_7a];
V_7a_p_span_4=[(c_1_2+D_1(4)).*a_1_7a -c_1_2.*a_2_7a zeros(823543,1) zeros(823543,1) zeros(823543,1); -c_1_2.*a_1_7a (c_1_2+c_2_3+D_2(4)).*a_2_7a -c_2_3.*a_3_7a zeros(823543,1) zeros(823543,1); zeros(823543,1) -c_2_3.*a_2_7a (c_2_3+c_3_4+D_3(4)).*a_3_7a -c_3_4.*a_4_7a zeros(823543,1); zeros(823543,1) zeros(823543,1) -c_3_4.*a_3_7a (c_3_4+c_4_5+D_4(4)).*a_4_7a -c_4_5.*a_5_7a; zeros(823543,1) zeros(823543,1) zeros(823543,1) -c_4_5.*a_4_7a (c_4_5+D_5(4)).*a_5_7a];
V_7a_p_span_5=[(c_1_2+D_1(5)).*a_1_7a -c_1_2.*a_2_7a zeros(823543,1) zeros(823543,1) zeros(823543,1); -c_1_2.*a_1_7a (c_1_2+c_2_3+D_2(5)).*a_2_7a -c_2_3.*a_3_7a zeros(823543,1) zeros(823543,1); zeros(823543,1) -c_2_3.*a_2_7a (c_2_3+c_3_4+D_3(5)).*a_3_7a -c_3_4.*a_4_7a zeros(823543,1); zeros(823543,1) zeros(823543,1) -c_3_4.*a_3_7a (c_3_4+c_4_5+D_4(5)).*a_4_7a -c_4_5.*a_5_7a; zeros(823543,1) zeros(823543,1) zeros(823543,1) -c_4_5.*a_4_7a (c_4_5+D_5(5)).*a_5_7a];
V_7a_p_span_6=[(c_1_2+D_1(6)).*a_1_7a -c_1_2.*a_2_7a zeros(823543,1) zeros(823543,1) zeros(823543,1); -c_1_2.*a_1_7a (c_1_2+c_2_3+D_2(6)).*a_2_7a -c_2_3.*a_3_7a zeros(823543,1) zeros(823543,1); zeros(823543,1) -c_2_3.*a_2_7a (c_2_3+c_3_4+D_3(6)).*a_3_7a -c_3_4.*a_4_7a zeros(823543,1); zeros(823543,1) zeros(823543,1) -c_3_4.*a_3_7a (c_3_4+c_4_5+D_4(6)).*a_4_7a -c_4_5.*a_5_7a; zeros(823543,1) zeros(823543,1) zeros(823543,1) -c_4_5.*a_4_7a (c_4_5+D_5(6)).*a_5_7a];
V_7a_p_span_7=[(c_1_2+D_1(7)).*a_1_7a -c_1_2.*a_2_7a zeros(823543,1) zeros(823543,1) zeros(823543,1); -c_1_2.*a_1_7a (c_1_2+c_2_3+D_2(7)).*a_2_7a -c_2_3.*a_3_7a zeros(823543,1) zeros(823543,1); zeros(823543,1) -c_2_3.*a_2_7a (c_2_3+c_3_4+D_3(7)).*a_3_7a -c_3_4.*a_4_7a zeros(823543,1); zeros(823543,1) zeros(823543,1) -c_3_4.*a_3_7a (c_3_4+c_4_5+D_4(7)).*a_4_7a -c_4_5.*a_5_7a; zeros(823543,1) zeros(823543,1) zeros(823543,1) -c_4_5.*a_4_7a (c_4_5+D_5(7)).*a_5_7a];
%S-Vector [(5x1] where every element is a (823543x1) vector
S_7a_p=[-c_1_2.*(a_2_7a-a_1_7a);-c_2_3.*(a_3_7a-a_2_7a)+c_1_2.*(a_2_7a-a_1_7a);-c_3_4.*(a_4_7a-a_3_7a)+c_2_3.*(a_3_7a-a_2_7a);-c_4_5.*(a_5_7a-a_4_7a)+c_3_4.*(a_4_7a-a_3_7a);c_4_5.*(a_5_7a-a_4_7a)];
n_1=(1:1:823543)';
V_7a_p_span_1_n=V_7a_p_span_1([n_1, length(n_1)+n_1, 2*length(n_1)+n_1,3*length(n_1)+n_1,4*length(n_1)+n_1],:);
S_7a_p_n=S_7a_p([n_1, length(n_1)+n_1, 2*length(n_1)+n_1, 3*length(n_1)+n_1, 4*length(n_1)+n_1],:);
gamma_7a_n_span_1=pinv(V_7a_p_span_1_n)*S_7a_p_n;
Shadaab Siddiqie
Shadaab Siddiqie 2020년 11월 20일
편집: Shadaab Siddiqie 2020년 11월 20일
You can still vectorize it. One example would be:
c_1_2=width*G./depth_7a_p_1.*10^3;
c_2_3=width*G./depth_7a_p_2.*10^3;
c_3_4=width*G./depth_7a_p_3.*10^3;
c_4_5=width*G./depth_7a_p_4.*10^3;
%insted of above code you can convert depth_7a_p_1,depth_7a_p_2,..,depth_7a_p_4 into a matrix
C = width*G./D.*10^3;
% Here D = [depth_7a_p_1 ; depth_7a_p_2 ;depth_7a_p_3 ;depth_7a_p_4]
Dont create depth_7a_p_1,depth_7a_p_2,..,depth_7a_p_4 at all create D directly from depth_7a_p.

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

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by