Why do i get the error: Array indices must be positive integers or logical values?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Stephen23
il 10 Dic 2021
Modificato: Stephen23
il 10 Dic 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
Risposta accettata
Voss
il 5 Dic 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Line Plots in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!