Uning Only Interger Values

1 visualización (últimos 30 días)
JWalker
JWalker el 1 de Dic. de 2018
Comentada: madhan ravi el 1 de Dic. de 2018
I am trying to index an array based on several values, using another array(Dt). This means I need to make sure all my values in Dt being used to index are interger values so I need to remove the values that are not intergers from Dt. Is there a way to do this directly?
Alternatively as Dt is being generated by Dt = Tf/nSteps; where Tf is a constant and nSteps = 1:1:20; is there a way to insure Dt only takes the interger values of Tf/nSteps?
Any help is appreciated.
  2 comentarios
KALYAN ACHARJYA
KALYAN ACHARJYA el 1 de Dic. de 2018
Can you explain more with array and index example?
JWalker
JWalker el 1 de Dic. de 2018
This is the section of code I'm working on currently, It doesn't have variable definitions but here:
for nSteps = 1:1:40
Dt = Tf/nSteps; %Makes Dt step size foe new steps
DtInt = floor(Dt); %Makes Dt Intergers
DtInt= unique(DtInt); %Makes unique intergers
T0=T; %Resets start temp of object
EulerTemp = zeros(1,nSteps);
EulerTime = zeros(1,nSteps);
EulerTemp(1) = T0;
EulerTime(1) = 0;
tstart=0;
for EulerLoop = DtInt:DtInt:Tf
DT = -K*(T0-Te)*Dt;
T0 = T0+DT;
tstart = EulerLoop;
EulerTemp(1+EulerLoop/DtInt) = T0;
EulerTime(1+EulerLoop/DtInt) = tstart;
end
PercentError = abs(EulerTemp-ExactTemp)/ExactTemp;
end

Iniciar sesión para comentar.

Respuesta aceptada

YT
YT el 1 de Dic. de 2018
You could use round(), floor(), ceil() to first round the floats to integers and then use unique() to remove possible duplicates
Tf = 500; %constant
nSteps = 1:1:20; %steps
Dt = Tf./nSteps
unique(round(Dt))
ans =
25 26 28 29 31 33 36 38 42 45 50 56 63 71 83 100 125 167 250 500
  2 comentarios
JWalker
JWalker el 1 de Dic. de 2018
I literaly just realised that and finished coding that. Can I just check the code for that would be:
nSteps = 1:1:40
Dt = Tf/nSteps; %Makes Dt step size foe new steps
DtInt = floor(Dt); %Makes Dt Intergers
DtInt= unique(DtInt); %Makes unique intergers
madhan ravi
madhan ravi el 1 de Dic. de 2018
Dt = Tf./nSteps;

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Preprocessing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by