开发者

sorting a timer in matlab

开发者 https://www.devze.com 2022-12-28 14:31 出处:网络
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 resultmy timing gets mixed.

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 开发者_如何学Pythonthe 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.


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))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号