필터 지우기
필터 지우기

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