Nested For loop with Cell Arrays

3 visualizaciones (últimos 30 días)
Alec Carruthers
Alec Carruthers el 7 de Abr. de 2018
Respondida: Bio_Ing_Sapienza el 11 de Dic. de 2018
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]);

Respuestas (2)

Venkata Siva Krishna Madala
Venkata Siva Krishna Madala el 10 de Abr. de 2018
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

Bio_Ing_Sapienza
Bio_Ing_Sapienza el 11 de Dic. de 2018
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

Community Treasure Hunt

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

Start Hunting!

Translated by