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 个评论

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.....
is 'data' a vector, or is it a matrix?
The code appears to be looping replacing outiers with the mean of the data, until finally there are no more outliers.
it is a vector.. but the problem is i want to replicate this command in R...
So, what changes i should make??
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.
thank you for your reply...
does it make sense to use repeat and while loop both at a time??
should i use it?
can you please give me an idea about any looping algorithm??
which loop has to be used now?
while or something else..???
Hi Sher, I don't know R and redoing this in R is not really within the scope of this website.
okay thank you so much for your quick response.. :)

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

版本

R2017b

标签

提问:

2019-12-24

评论:

2019-12-29

Community Treasure Hunt

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

Start Hunting!

Translated by