In terms of making any suggestions, I think you just need to practice writing code in Matlab using built in features such as array slicing to minimize the amount of looping you need to perform. Of course, for complex problems like yours you are probably going to need some looping so it is very important you understand the flow of your program and different ways you can implement this. I found the easiest way to learn any new language is to write a program to perform something that you can easily check with another program. My first program in Matlab was a frame analysis program and it was a total piece of rubbish although it did give me the right answer (just took about 50 times the amount of code that I can do it in now).
Keep at it and you will have a very handy skill at the end of the day.
Jul 9th 2010, 08:11 AM
Hi Elbarto, sorry to bother you again, but I am stuck., completely stuck. I read a book called : Mastering Matlab 7, but I found that implementing in matlab a code that can do what I told you, is way more advanced than the book and my knoledge. I am lost. What I could do ?
Please help me
Jul 9th 2010, 05:24 PM
Your code your are trying to implement isn't exactly a good place to start for a beginner. Once you Identify and bad data points, you function *should* be able to be written with a pretty basic programming approach however stinging this all into usable code is the challenge. May I ask what the code is for - Educational, Commercial or Personal? I might be able to help out a bit more on the subject, but it would be extremely useful if I could see some real data. For example, are the data points sampled at regular time intervals as it doesn't appear so in your xls file.
Jul 9th 2010, 05:48 PM
Try something like this:
(1) Bad data points are not at the start or end of the data set
(2) Data is sampled at a constant rate
See the graph for a comparison of the before and after data. Remember to put the xls file and my getnextdoor function is the same dirrectory as the file below when you run it.
fname = 'try.xls';
xls = xlsread(fname, sheetName);
Ref = xls(:,2);%get second row
BC = xls(:,3);%get thrid row
%calc abs of difference
ABS_Refj_Refi = abs(Ref(2:end)-Ref(1:end-1));
p = prctile(ABS_Refj_Refi,85);
bad_flag = find(ABS_Refj_Refi > p);%position of bad data
bad_index_list = getNextDoor(bad_flag);%see my custom function
%we get all indexes that are bad and how many consective indexes there are.
out = BC;%save new variable
for i = 1:length(bad_index_list(:,1))% for each section of bad data
bad_index = bad_index_list(i,1);%bad index list
num_consec = bad_index_list(i,2);%how many times they repeat
L = out(bad_index-1);%left value
R = out(bad_index+num_consec+1);%right value