필터 지우기
필터 지우기

How can I update values from a variable that updates constantly to a table?

조회 수: 2 (최근 30일)
ESIDOR PASHAJ
ESIDOR PASHAJ 2018년 2월 1일
댓글: Walter Roberson 2018년 2월 1일
Basically, I am looking at a video with 1200 frames. I have a function which only picks out the frames of interest (e.g. frame 61,101,175,etc...). How do I plot all the values of 'frame' on a table? (Keep in mind that the value of 'frame' updates!)
  댓글 수: 3
ESIDOR PASHAJ
ESIDOR PASHAJ 2018년 2월 1일
Hi Bob. That's correct. I tried to do that but instead of saving all the different values of 'frame', it only saves one (the last one). I would appreciate if you could help with some code as I'm pretty new to Matlab. Thanks
Bob Thompson
Bob Thompson 2018년 2월 1일
What Walter Roberson posted is basically what I was thinking. Essentially, within your for loop for all frames you will want to have a condition such that IF an interesting frame is found THEN an index value is increased, and the data for the frame is stored as that new increased index in your storage array.
By having the index increase within the if statement it should only increase when an interesting frame is found, rather than for all frames in the movie. This will help keep your array of interesting frames short, but the increasing index will ensure the data is added to the array, rather than overwriting.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2018년 2월 1일
number_of_frames - 1200;
interesting_frames = cell(number_of_frames, 1);
interesting_frame_numbers = zeros(number_of_frames, 1);
interesting_frames_found = 0;
for frame_number = 1 : number_of_frames
thisframe = ... get frame #frame_number from video object
if frame_is_interesting(thisframe)
interesting_frames_found = interesting_frames_found + 1;
interesting_frames{interesting_frames_found} = thisframe;
interesting_frame_numbers(interesting_frames_found) = frame_number;
end
end
interesting_frames(interesting_frames_found+1:end) = [];
interesting_frame_numbers(interesting_frames_found+1:end) = [];
  댓글 수: 1
Walter Roberson
Walter Roberson 2018년 2월 1일
Note that I pre-allocate here to the maximum size, and then shorten down to the size actually used. If you knew a maximum smaller number of "interesting" frames you could use that. The overhead per cell entry is about 104 bytes so cells are not free -- but a wasted cell is a lot more efficient than having to copy all of the data around because you were expanding an array on the fly.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by