Why do i get the error: Array indices must be positive integers or logical values?
1 view (last 30 days)
Show older comments
Hi, ive been trying to plot 3 sets of data on the same graph plot and i keep getting this error message :Array indices must be positive integers or logical values in my for loop
1 Comment
Stephen23
on 10 Dec 2021
Edited: Stephen23
on 10 Dec 2021
Original question by Sebastion Sunny retrieved from Google Cache:
Why do i get the error: Array indices must be positive integers or logical values?
Hi, ive been trying to plot 3 sets of data on the same graph plot and i keep getting this error message :Array indices must be positive integers or logical values in my for loop
WindSpeeds = linspace(0,30,300);%m/s
deltaT = 0.01;
time = 0:deltaT:300;
%preallocation
rotorTorque = zeros(length(WindSpeeds),1); %Nm
turbinePower = zeros(length(WindSpeeds),1);
generatorTorque = zeros(length(WindSpeeds),1);
omegaRotor = zeros(length(WindSpeeds),1);
%eulers method
for i = 2:length(time)
omegaRotor(i) = omegaRotor(i-1) + deltaT((windTurbineRotorModel(WindSpeeds,Ct,D,Vcutout,Vrated,Vcutin))-(k*omegaRotor(i-1).^2)/j);
end
this is the code ive written at the moment
Thank you
Accepted Answer
Voss
on 5 Dec 2021
This expression in the loop:
deltaT((windTurbineRotorModel(WindSpeeds,Ct,D,Vcutout,Vrated,Vcutin))-(k*omegaRotor(i-1).^2)/j)
says to get the elements of deltaT with index (or indices) equal to the value of:
(windTurbineRotorModel(WindSpeeds,Ct,D,Vcutout,Vrated,Vcutin))-(k*omegaRotor(i-1).^2)/j
I don't know what the value of that expression is because most of those variables are undefined, but given that deltaT is a scalar variable, I would guess that indexing it like that is not what you mean to be doing.
More Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!