adding rows somewhere in the array

1 Ansicht (letzte 30 Tage)
tafteh
tafteh am 4 Mär. 2013
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

Akzeptierte Antwort

Brian B
Brian B am 4 Mär. 2013
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 Kommentare
tafteh
tafteh am 4 Mär. 2013
great, allow me to try this out.
tafteh
tafteh am 4 Mär. 2013
thanks, it works. appreciate it

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Brian B
Brian B am 4 Mär. 2013
Bearbeitet: Brian B am 4 Mär. 2013
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);

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by