adding rows somewhere in the array

1 次查看(过去 30 天)
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.

更多回答(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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by