Why do i get the error: Array indices must be positive integers or logical values?

1 visualización (últimos 30 días)
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 comentario
Stephen23
Stephen23 el 10 de Dic. de 2021
Editada: Stephen23 el 10 de Dic. de 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

Iniciar sesión para comentar.

Respuesta aceptada

Voss
Voss el 5 de Dic. de 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.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by