Using if statement to redefine results during for loop
Show older comments
Ok so I am trying to perform a vortex panel method calculation for a school project and am running two iterations for two different number of panels (i.e. 8 panels & 16 panels). Since I can't just store the results in a final matrix due to each iteration resulting in different matrix dimensions, I am trying to run an if elseif loop within the overall for loop as seen below that would redifine the results of each iteration in variables labeled for that specific panel count. For some reason though when I run the code and try to call the redefined variables it tells me that they are all unrecognizable. Hopefully this is a minor fix that I am just not seeing but I am overall very confused as to what the issue is. It's almost as if the second if loop is being passed over which doesn't make sense since i am using a similar method to change the panel geometries at the beginning of the for loop as shown and that works.
for p = 1:2
if p == 1 %Wing Geometry for 8 Panels
XLE = [0.0; 0.0; 5.52; 12.0; 20.01; 28.06; 36.10; 44.25; 48.61];
YLE = [0.0; 6.87; 12.88; 20.00; 30.00; 40.00; 50.00; 60.00; 65.56];
XTE = [33.03; 33.03; 33.03; 36.15; 41.01; 45.64; 50.43; 55.11; 57.80];
YTE = [0.0; 6.87; 12.88; 20.00; 30.00; 40.00; 50.00; 60.00; 65.56];
elseif p == 2 %Wing Geometry for 16 Panels
XLE = [0.0; 0.0; 0.0; 2.76; 5.52; 8.76; 12.0; 16.005; 20.01; 24.035; 28.06; 32.08; 36.1; 40.175; 44.25; 46.43; 48.61];
YLE = [0.0; 3.435; 6.87; 9.875; 12.88; 16.44; 20.0; 25.0; 30.0; 35.0; 40.0; 45.0; 50.0; 55.0; 60.0; 62.78; 65.56];
XTE = [33.03; 33.03; 33.03; 33.03; 33.03; 34.59; 36.15; 38.58; 41.01; 43.325; 45.64; 48.035; 50.43; 52.77; 55.11; 56.455; 57.80];
YTE = [0.0; 3.435; 6.87; 9.875; 12.88; 16.44; 20.0; 25.0; 30.0; 35.0; 40.0; 45.0; 50.0; 55.0; 60.0; 62.78; 65.56];
end
... a bunch of code that works...
if p == 1;
y_8p = C(:,2); %8x1 matrix
Gamma_8p = Gamma; %8x1 matrix
CL_8p = CL; %value
CDv_8p = CDv;
GammaIdeal_8p = GammaIdeal;
CL_Ideal_8p = CL_Ideal;
CDv_Ideal_8p = CDv_Ideal
elseif p == 2;
y_16p = C(:,2);
Gamma_16p = Gamma;
CL_16p = CL;
CDv_16p = CDv;
GammaIdeal_16p = GammaIdeal;
CL_Ideal_16p = CL_Ideal;
CDv_Ideal_16p = CDv_Ideal
end
p = p + 1;
end
5 Comments
David Fletcher
on 18 Apr 2021
Edited: David Fletcher
on 18 Apr 2021
The variables referred to in the second if block aren't defined anywhere in this code segment - presumably they are defined elsewhere? C, Gamma, CL, CDv ... etc. (maybe in that bit that says ...a bunch of code that works?)
Also, it's probably nothing to do with the issue, but I'm not sure why you are incrementing p near the end? It's a for loop - it increments itself.
Ryan Coney
on 18 Apr 2021
Ryan Coney
on 18 Apr 2021
David Fletcher
on 18 Apr 2021
Ok, but without those definitions nobody else can run the code. If I take out that second if block that I don't have the definitions for, when I run it the first block correctly allocates the XLE, YLE, XTE and YTE values on each iteration - so the problem would seem to be somewhere in the bit that is omitted. Maybe someone else can see something I can't.
Ryan Coney
on 18 Apr 2021
Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!