Azzera filtri
Azzera filtri

Uning Only Interger Values

2 visualizzazioni (ultimi 30 giorni)
JWalker
JWalker il 1 Dic 2018
Commentato: madhan ravi il 1 Dic 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 Commenti
KALYAN ACHARJYA
KALYAN ACHARJYA il 1 Dic 2018
Can you explain more with array and index example?
JWalker
JWalker il 1 Dic 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

Accedi per commentare.

Risposta accettata

YT
YT il 1 Dic 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 Commenti
JWalker
JWalker il 1 Dic 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 il 1 Dic 2018
Dt = Tf./nSteps;

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Discrete Data Plots in Help Center e File Exchange

Tag

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by