Nested For loop with Cell Arrays

Alec Carruthers

Alec Carruthers (view profile)

さんによって質問されました 2018 年 4 月 7 日

Bio_Ing_Sapienza (view profile)

さんによって 回答されました 2018 年 12 月 11 日
This code runs ok with one for loop, but when I introduce a for loop for "AR" within the original, I get an error of: "Out of Range Subscript." I was using an array for DelM because that was the only was I could solve the equation, within the for loop, symbolically (using a symbolic variable). How do I modify my set up to loop through all the j iterations for one i iteration without an error? This is just a part of the code.
Thank you
AR = [5:.2:12];
p = length(AR);
Airfoil = 2; % Supercritical = 1, Conventional = 2.
Engine = 3;
% Assuming a Cl value so need a for loop.
CL=[.45:.005:.6];
n = length(CL);
DelM = cell(p,[]);
syms x
syms y
for i= 1:n
for j = 1:p
if Airfoil == 1 % Supercritical
DelM{i,j} = vpasolve((CL(i,j)==((-2*10^9)*x^6)-((1*10^8)*x^5)-((2*10^6)*x^4)-((2632.1*x^3)+124.37*x^2)-(5.8637*x)+.5475),x,[-.01 .015]);
end
if Airfoil == 2 %Conventional
DelM{i,j} = vpasolve((CL(i,j)==(-5.1087*x^2)-(2.9657*x)+.5509),x,[-.02 .04]);

0 件のコメント

サインイン to comment.

2 件の回答

Venkata Siva Krishna Madala (view profile)

2018 年 4 月 10 日

Hi Alec,
I debugged your code and its actually a pretty small mistake.
AR = [5:.2:12];
p = length(AR);
Airfoil = 2; % Supercritical = 1, Conventional = 2.
Engine = 3;
% Assuming a Cl value so need a for loop.
CL=[.45:.005:.6];
n = length(CL);
DelM = cell(n,p);
syms x
syms y
for i= 1:n
for j = 1:p
if Airfoil == 1 % Supercritical
DelM{i,j} = vpasolve((CL(i)==((-2*10^9)*x^6)-((1*10^8)*x^5)-((2*10^6)*x^4)-((2632.1*x^3)+124.37*x^2)-(5.8637*x)+.5475),x,[-.01 .015]);
end
if Airfoil == 2 %Conventional
DelM{i,j} = vpasolve((CL(i)==(-5.1087*x^2)-(2.9657*x)+.5509),x,[-.02 .04]);
end
end
end
Thanks,

0 件のコメント

サインイン to comment.

Bio_Ing_Sapienza (view profile)

2018 年 12 月 11 日

for i=1:numel(Translated_ref) %Translated_ref is a cell array of 5515 cell each one containing a sequence
mol=0
for j=1:round(Translated_ref{i}./w)
mol=mol+1
T{i,j}=Translated_ref{i}(1,1+mol*w-w:mol*15);
end
end
I have quite a similar problem. Anyone can help me to fix it?
%Index in position 2 exceeds array bounds (must
%not exceed 15).
%Error in Untitled4 (line 9)
%T{i,j}=Translated_ref{i,1}(1,1+mol*w-w:mol*15);
%This is the error Matlan returns me
Thank you in advance

0 件のコメント

サインイン to comment.