Nested For loop with Cell Arrays
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Venkata Siva Krishna Madala
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,
Krishna Madala
0 件のコメント
Bio_Ing_Sapienza
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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!