Matlab Loop Errors

  • #1

Main Question or Discussion Point

I'm trying to write a matlab code but I get an error message which I'm not sure why. The code is follows as,

%%%%% Code %%%%%

for i = 1:1:v;
for j = 1:0.1:a

TSR(i,j)=wR/i;

end
end

%%%%% Code %%%%%

Here 'a' is taken as 90 degrees, which represents blade path of a vertical axis wind turbine and 'v' is taken as the velocity (m/s) of air and wR (omega) is taken as 5 which is the angular speed of the wind turbine. What I'm trying to estimate is the the Tip Speed Ratio of a vertical axis wind turbine at different blade path angle which corresponds to different speeds. The equation is given below which calculates the Tip Speed Ratio.

TSR = (wR/v) = [wind turbine angular speed / speed of wind]

The error message that I'm getting is given below.

??? Attempted to access TSR(1.1,1); index must be a positive integer or logical.

Error in ==> Experiment at 57
TSR(i,j)=wR/i;


Could some one give any suggestions to correct my calculations.
 

Answers and Replies

  • #2
69
1
I'm trying to write a matlab code but I get an error message which I'm not sure why. The code is follows as,

%%%%% Code %%%%%

for i = 1:1:v;
for j = 1:0.1:a

TSR(i,j)=wR/i;

end
end

%%%%% Code %%%%%

Here 'a' is taken as 90 degrees, which represents blade path of a vertical axis wind turbine and 'v' is taken as the velocity (m/s) of air and wR (omega) is taken as 5 which is the angular speed of the wind turbine. What I'm trying to estimate is the the Tip Speed Ratio of a vertical axis wind turbine at different blade path angle which corresponds to different speeds. The equation is given below which calculates the Tip Speed Ratio.

TSR = (wR/v) = [wind turbine angular speed / speed of wind]

The error message that I'm getting is given below.

??? Attempted to access TSR(1.1,1); index must be a positive integer or logical.

Error in ==> Experiment at 57
TSR(i,j)=wR/i;


Could some one give any suggestions to correct my calculations.
I believe it's because you're attempting an index an array with a non-integer; by incrementing j in steps of 0.1, you're trying call out a 1.1'th element in TSR (i.e. the elements must be numbered 1, 2, 3, ...)
 
  • #3
jhae2.718
Gold Member
1,161
20
Is TSR a previously defined matrix? If you're trying to store elements, as it's already been stated you must use a positive integer.

It doesn't look like you are using j in your program.
 

Related Threads for: Matlab Loop Errors

  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
2
Views
4K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
3
Views
722
  • Last Post
Replies
17
Views
991
  • Last Post
Replies
4
Views
700
Top