How to save every iteration of a structured array in a loop in a function?

I am using a fairly complex function to stabilize images that was written by Daniel Bourgault & others to stabilize imagery https://gitlasso.uqar.ca/bourda02/g_rect.
It works perfectly, but I need to develop a translation matrix from this program, so it is important that I can write the translation variables out to the workspace or save them and load them later. I am having trouble writing out more than just one iteration. I have looked up several ways of doing this, but I have not had much success. I am wondering if it is because I am missing something necessary when using "for iter = 1:niter", or if I should be saving this structured array from another function?
Here is the for loop where the variable is called in from another function. I need to save every iteration of "motion", which is a structured array with two variables (A and T).
I have uploaded the two main functions out of this set that I am interested in (g_stabilize(primary function) and g_videostabilize). Thank you for the help!
for iter = 1:niter
[motion,stable] = g_videostabilize(frames,roi,L);
frames(1).im = stable(1).im;
end

8 Commenti

Is your indexing on frames always (1)?
Thanks Walter, sorry for the delay in responding, our servers went down and I couldn't access matlab until just now. Adding in a line to save the output is still only resulting in the motion of one image being stored instead of all the images as it loops through. Perhaps I am just not trying to save the structure at the correct location in the code.
for iter = 1:niter
[motion,stable] = g_videostabilize(frames,roi,L);
frames(iter).motion = motion;
frames(iter).im = stable(1).im;
end
The motion array is still only saving with one value in it. I have tried saving in other places as well with the same result. The code applies the translation to an unlimited number of images so I am not sure why I am not able to write these values out.
for iter = 1:niter
[motion{iter}, stable{iter}] = g_videostabilize(frames,roi,L);
frames(iter).im = stable{iter}(1).im;
end
That is causing the error, "Struct contents reference from a non-struct array object. " on the following line
im_stable = g_warp(im1,motion.A,motion.T);

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su MATLAB in Centro assistenza e File Exchange

Richiesto:

il 10 Mag 2018

Commentato:

il 15 Mag 2018

Community Treasure Hunt

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

Start Hunting!

Translated by