comparing two vectos and inserting where numbers are missing
2 ビュー (過去 30 日間)
古いコメントを表示
Hi, Have tried various things. I have 2 vectors - a control vector called time (say m by 1) and a matrix call it b of (n by 2) m >n for example
time b
1000 1000 5
2000 2000 10
3000 4000 15
4000 5000 18
5000 6000 20
6000 8000 25
7000 9000 30
8000
9000
10000
i want matrix b to fill in the missing times (ie where missing) and a corresponding value in coloumn 2 of 0
so the output would look like
1000 5
2000 10
3000 0 (this line is new)
4000 15
5000 18
6000 20
7000 0 (this line is new)
8000 25
9000 30
10000 0 (this line is new)
i have mangaged to index the missing spaces with
ind = find(ismember(time,b(:,1)) ==0) which returns 3 7 10 ie the missing places but not sure where to go. more than happy to ignore totlaly what i have done so far.
0 件のコメント
採用された回答
Jan
2013 年 3 月 5 日
time = (1000:1000:10000).';
b = [1000 5; ...
2000 10; ...
4000 15; ...
5000 18; ...
6000 20; ...
8000 25; ...
9000 30];
found = ismember(time, b(:, 1));
result(found, 2) = b(:, 2);
result(:, 1) = time;
0 件のコメント
その他の回答 (1 件)
Azzi Abdelmalek
2013 年 3 月 5 日
編集済み: Azzi Abdelmalek
2013 年 3 月 5 日
b=[1000 5
2000 10
3000 0
4000 15
5000 18
6000 20
7000 0
8000 25
9000 30
10000 0 ]
t=b(:,1)
y=b(:,2)
t1=t(find(y));
y1=y(find(y));
yi=interp1(t1,y1,t)
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!