Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
ESIDOR PASHAJ
ESIDOR PASHAJ il 1 Feb 2018
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 il 1 Feb 2018
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.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 1 Feb 2018
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 Commento
Walter Roberson
Walter Roberson il 1 Feb 2018
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.

Accedi per commentare.

Categorie

Scopri di più su Tables in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by