Marco,
try.xls needs to be in the same directory as the code that you are executing or on the search path. It might sound complicated but it is a very simple concept that google will help you understand. The error you are getting is because matlab cant find the file.
The Variable "C" is the same as the last column in your first spreadsheet, but in this case any bad data was removed. Matlab does really do "blank cells" in a matrix or vector (you can use a cell array but I avoid them if I can). Interpolating instead of deleting bad data is possible, and probably best done with a for loop as you suggested. This is a bit more involved tho as you will need to
1) Loop through data and find bad point
2)determine number of consecutive bad points
3)interpolate between points (see interp function)
It is certainly achievable. I started having a play around to see how you can find our how many times consecutive numbers are repeated (Captain Black could prob do it in one line of code). I used a recursive function to find the matrix, you will need to save the function in the same dirrectory as the other files with the correct file name:
My Code:
Code:
clc;clear;
fname = 'try.xls';
sheetName='Sheet1';
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));
%95th percentile
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.
my function (save as getNextDoor.m)
Code:
function a = getNextDoor(vec,mat)
%returns index of first index and how many occurances follow
%[first_index number_of_consective_numbers)
if nargin == 1;mat = [];end
if isempty(vec);
a = mat;
return
end%base case
if isempty(mat) || vec(1) ~= mat(end,1)+mat(end,2)+1;
mat = [mat;[vec(1) 0]];
vec(1) = [];
a = getNextDoor(vec,mat);
else
vec(1) = [];
mat(end,2) = mat(end,2) + 1;
a = getNextDoor(vec,mat);
end I have run out of time tonight to try and get a solution so you can have a play with the code and see how that goes. Matlab and excel give different values for the 95th percentile so I have used the 85th percentile to create more bad data while testing the code.
Regards Elbarto
(Sorry I made this post in a bit of a rush so it is pretty sloppy)