I have this error Index in position 1 exceeds array bounds.

I have a script, when I run it, I have the eabove error:
Index in position 1 exceeds array bounds.
Error in BEM (line 245)
angle=foilarray{airfoil,1}(aoacounter,1);
(Line 245 is this one) ----> angle=foilarray{airfoil,1}(aoacounter,1);
I read solution regarding this topic but no answer was helpful

6 Comments

Before the command
angle=foilarray{airfoil,1}(aoacounter,1)
insert the lines
foilarray{airfoil,1}
size(foilarray{airfoil,1})
aoacounter
What's the output from MATLAB ?
dbstop if error
run the code. When it stops examine
size(foilarray)
size(foilarray{1})
Hi Walter,
Thank you for your suggestion. Below the answer
K>> foilarray
foilarray =
8×1 cell array
{[ 0]}
{[ 0]}
{0×4 double}
{0×4 double}
{0×4 double}
{0×4 double}
{0×4 double}
{0×4 double}
K>> aoacounter
aoacounter =
1
K>> size(foilarray)
ans =
8 1
K>> size(foilarray{1})
ans =
1 1
But still don't know how to fix this error :
K>> angle=foilarray{airfoil,1}(aoacounter,1)
Index in position 1 exceeds array bounds.
245 angle=foilarray{airfoil,1}(aoacounter,1);
Regards,
Rigo
Your code assumes that each foilarray cell entry contains at least one value, but foilarray{3,1} is empty.
Hi Walter,
I have attached the script to this mail, please can you have a look, I don't understand why foilarray{3,1} is empty
Regards,
Rigo
We do not have your input files, and we do not know what parameters you are calling the function with.

Sign in to comment.

 Accepted Answer

Every one of your .dat files have text headers on them, but in every case you are using textscan() with %f format and no Headerlines
For those files, you should be using
'HeaderLines', 53

4 Comments

Thank you Walter. It works
I tried to display the value of Thrust and Torque, but those values are not display, any explanation
disp(accumulatedthrust)
disp(accumulatedtorque)
total_thrust(i,1)=accumulatedthrust;
total_torque(i,1)=accumulatedtorque;
Thans again
Those two disp() are working. You do not happen to disp() any text describing what is being output, but they are output, just two numbers floating there without context.
You have
U=8; % Added by RIGO
n=length(U);
with U being a scalar, n will be 1, so
for i=1:n
is only going to do one iteration.
I have removed this line
U=8; % Added by RIGO. U is already define as input of this function.
Sorry, this statment is not clear: with U being a scalar, n will be 1, so for i=1:n is only going to do one iteration.
Thanks the disp() shows both values: Thrust and Torque
Hi Walter,
Great, thanks again, it works and I understood the notion about the scalar definition and the number of iteration
Regards,
Rigo

Sign in to comment.

More Answers (1)

Sorry, but the dat file are unsupported on Matlab forum. I changed the file extension to txt, just change back to dat file before use in this script.
U = 8m/s
Time = 100s
B = 3
Omega = 1.0159
rho = 1.25
maxdev = 0.00001
Regards,
Rigo

Categories

Products

Release

R2019b

Community Treasure Hunt

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

Start Hunting!