repflag=true;

hi there.. i am converting matlab codes which have "repflag=true" i don't understand this kindly someone guide me...
thanks in advance.

10 Commenti

Hi Sher,
impossible to say since you have not provided any context. Regardless, what you could do at least as well as anyone on this site is scan down through the rest of the code until you find
if repflag % or possibly if repflag==true
blah
blah
blah
end
and try to scope out what it does.
okay i can understand ... so this is the full coding what i am asking for...
#########################
#####Recursive filter on prices
function [ dataf, spikes, drops ] = of_rfp(data, param)
if(nargin < 2 || isempty(param))
ns = 3;
else
ns = param;
end
outrep = mean(data);
spikes = zeros(size(data));
drops = zeros(size(data));
dataf = data;
repflag = true;
while(repflag)
spikestmp = logical(dataf >= mean(dataf)+ns*std(dataf));
dropstmp = logical(dataf <= mean(dataf)-ns*std(dataf));
if(nnz(spikestmp))
dataf(spikestmp) = outrep;
end
if(nnz(dropstmp))
dataf(dropstmp) = outrep;
end
if(~nnz(spikestmp) && ~nnz(dropstmp))
repflag = false;
end
spikes = spikes + spikestmp;
drops = drops+ dropstmp;
end
spikes = (spikes == 1);
drops = (drops == 1);
end
please give me any suggestion .. thanks for replying.....
David Goodmanson
David Goodmanson il 29 Dic 2019
is 'data' a vector, or is it a matrix?
Walter Roberson
Walter Roberson il 29 Dic 2019
The code appears to be looping replacing outiers with the mean of the data, until finally there are no more outliers.
Sher Akbar
Sher Akbar il 29 Dic 2019
it is a vector.. but the problem is i want to replicate this command in R...
So, what changes i should make??
David Goodmanson
David Goodmanson il 29 Dic 2019
HI Sher,
best to figure out what it's doing, then write a new version in R. The comment says it's recursion, but it's really iteration.
Using ns = 3 as an example, then as Walter mentioned, take the outlier measurements that lie more than 3 standard deviations away from the mean, and replace them by the mean. That makes a new data set. Then find a new mean and standard deviation and repeat the process until there are no more outliers. Why someone would use that process is a question worth asking, if you don't know already.
During the process, count up the outliers on each side of the mean. The spikes = (spikes ==1) statement seems to be in order to avoid double counting any outliers, same for drops.
Sher Akbar
Sher Akbar il 29 Dic 2019
thank you for your reply...
does it make sense to use repeat and while loop both at a time??
should i use it?
Sher Akbar
Sher Akbar il 29 Dic 2019
can you please give me an idea about any looping algorithm??
which loop has to be used now?
while or something else..???
David Goodmanson
David Goodmanson il 29 Dic 2019
Hi Sher, I don't know R and redoing this in R is not really within the scope of this website.
Sher Akbar
Sher Akbar il 29 Dic 2019
okay thank you so much for your quick response.. :)

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Prodotti

Release

R2017b

Tag

Richiesto:

il 24 Dic 2019

Commentato:

il 29 Dic 2019

Community Treasure Hunt

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

Start Hunting!

Translated by