tags:

views:

53

answers:

1

ok it seems like a simple problem, but i am having problem I have a timer for each data set which resets improperly and as a result my timing gets mixed. Any ideas to correct it? without losing any data. Example

timer col ideally should be

timer , mine reads
1 3
2 4
3 5
4 6
5 1
6 2

how do i change the colum 2 or make a new colum which reads like colum 1 without changing the order of ther rows which have data this is just a example as my file lengths are 86000 long , also i have missing timers which i do not want to miss , this imples no data for that period of time.

thanks

EDIT: I do not want to change the other columns. The coulm 1 is the gps counter and so it does not sync with the comp timer due to some other issues. I just want to change the row one such that it goes from high to low without effecting other rows. also take care of missing pts ( if i did not care for missing pts simple n=1: max would work.

missing data in this case is indicated by missing timer. for example i have 4,5,8,9 with missing 6,7

Ok let me try to edit agian its a 8600x 80 matrix of data: timer is one row which should go from 0 to 8600 but timer starts at odd times , so i have start of data from middle , lets say 3400, so in the middle of day my timer goes to 0 and then back to 1. but my other rows are fine. I just need 2 plot other sets based on timer as time. i cannot use T= 1:length(file) as then it ignores missed time stamps ( timers )

for example my data reads like

timer , mine reads
1 3
2 4
3 5
4 8
5 9
8 1
9 2

so u can see time stamps 6,7 are missing. if i used n=1:length(file) i would have got 1 2 3 4 5 6 7 which is wrong i want 1 2 3 4 5 8 9

without changing the order of other rows , so i cannot use sort for the whole file.

+1  A: 

I assume the following problem

data says

3 100
4 101
5 102
NaN 0
1 104
2 105

You want

1 100
2 101
3 102
NaN 0
4 104
5 105

I'd solve the problem like this:

%# create test data
data = [3 100
    4 101
    5 102
    NaN 0
    1 104
    2 105];

%# find good rows (if missing data are indicated by zeros, use 
%# goodRows = data(:,1) > 0;
goodRows = isfinite(data(:,1));

%# count good rows
nGoodRows = sum(goodRows);

%# replace the first column with sequential numbers, but only in good rows
data(goodRows,1) = 1:nGoodRows;

data =

     1   100
     2   101
     3   102
   NaN     0
     4   104
     5   105

EDIT 1

Maybe I understand your question this time

data says

4 101
5 102
1 104
2 105

You want

1 4 101
2 5 102
4 1 104
5 2 105

This can be achieved the following way

%# test data
data = [4 101
    5 102
    1 104
    2 105];

%# use sort to get the correct order of the numbers and add it to the left of data
out = [sort(data(:,1)),data]

out =

     1     4   101
     2     5   102
     4     1   104
     5     2   105

EDIT 2

Note that out is the result from the solution in EDIT 1

It seems you want to plot the data so that there is no entry for missing values. One way to do this is to make a plot with dots - there won't be a dot for missing data.

plot(out(:,1),out(:,3),'.')

If you want to plot a line that is interrupted, you have to insert NaNs into out

%# create outNaN, that has NaN-rows for missing entries
outNaN = NaN(max(out(:,1)),size(out,2));
outNaN(out(:,1),:) = out;

%# plot
plot(out(:,1),out(:,3))
Jonas
No i do not want to change the order, i mean I just want to change the order of counter so it starts from 1 and goes to max , from top top to bottom. leaving other rows unchanged. And also acoount for missing rows
AP
I made another attempt at understanding your problem. If this is not what you want, can you please edit your questions so that it is similar to the problem statement in my posts, i.e. have both the input and the desired output?
Jonas
??? Error using ==> horzcatCAT arguments dimensions are notconsistent.this is the error i am getting for the ' out = [sort(data(:,1)),data] ' line
AP
@AP: This is bizarre, because when I copy-paste the solution to my command window and evaluate it, I get `out` with no problems. Maybe you need to transpose `data` first, i.e. write `data=data';` to make my example work on your input?
Jonas
I figured that, but it does not help my main problem, this is almost similar to writing T= 1: length(data)when i have missing timestamps ( timers ) this does not help when i plot. as it does not leave blank.
AP
@AP: Yes, it is almost similar to writing T=1:length(data). But it does answer the question you asked. Had you asked about plotting directly, I could have given you the answer directly. I have made two suggestions how you can plot the data so that there's 'nothing' for missing values.
Jonas
i guess i have confused everyone. I do not know why my timer when sorted does not match with the comp time stamps when i plot. All i really needed was plot (sort(data(:,8))/3600,data(:,9),'g')
AP

related questions