adding rows somewhere in the array

1 回表示 (過去 30 日間)
tafteh
tafteh 2013 年 3 月 4 日
Hi all,
I record the location of an object in 2D-screen in this format:
LOCATION = [x, y, time(cpu time), frame number];
I would like to use the frame number in future analysis as an index. However sometime I notice that the frame numbers are skipped and nunot recorded. I mean when I calculate the diff(frame_num) I get ans>1.
I thought I could resolve this issue by finding the location of those frame numbers that missed. then produce frame numbers and replicate the corresponding row values from what I have in the vector.
ex. frame_num = [1;2;3; 6;7;8; 15];
I find that I have no frame numbers between 3 and 6, and also between 8 and 15;
i want to create frame_num2 = [1; 2;3;4;5;6;7;8;9;10;11;12;13;14;15];
then for those frame numbers that I create I copy the corresponding values that I have. i.e. i copy the row of frame_number 3; for newly created frame_numbers 4 and 5.
Is there a way in matlab to find all the skipped frame numbers at once?
any idea?!
Thanks

採用された回答

Brian B
Brian B 2013 年 3 月 4 日
Then, when you want to build the complete LOCATION matrix, you can do something like
LOCATION2 = zeros(15, 4);
LOCATION2(:,1) = 1:15;
LOCATION2(LOCATION(:,1),:) = LOCATION;
to put the known values into the new matrix. Then you just have to fill in the other parts of the inserted rows.
  2 件のコメント
tafteh
tafteh 2013 年 3 月 4 日
great, allow me to try this out.
tafteh
tafteh 2013 年 3 月 4 日
thanks, it works. appreciate it

サインインしてコメントする。

その他の回答 (1 件)

Brian B
Brian B 2013 年 3 月 4 日
編集済み: Brian B 2013 年 3 月 4 日
Do you mean that you simply want to find which numbers are missing from frame_num? You can do that with
missing_nums = setdiff(1:15, frame_num);

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by