save each struct to vector-like format

Hi, i want to append each structs to the vector-like format.
And that struct will be a 'imregtform' function's output, 'tform'.
tform = {};
for i= X_dev
fl_c = fl(i);
fu_c = fu(i);
tform= imregtform(fl_c,fu_c,'rigid',optimizer,metric);
% I want to save that all tform during the for loop...
tform_list{end+1}= tform;
% is this right? when i do this, the error is occured at
% reference part of code which load this
end
save('tform_result.mat', 'tform_list');
Like the above code, during the for loop, new struct will made, and i want to save that new struct to vector-like format
(i don't know well about the matlab, so i don't know which format will appropriate to saving the struct)
i.e the final vector-like variable's each elemet will be a struct result
(p.s i want to save that final vector-like variable to .mat file, and load that file at another code, then take out each struct sequentialy. In this case,
is there a possibility that the value or shape of the struct may be damaged due to saving and loading? )
how can i do this? is there any good idea for this? and thank you for all responses.

1 个评论

It's unclear how you would be storing a series of images fl in a way that could be indexed fl(i). Perhaps you have fl as a cell array?

请先登录,再进行评论。

 采纳的回答

Matt J
Matt J 2023-11-3
编辑:Matt J 2023-11-3
I think you have a misunderstanding about what a struct is. None of the variables in your code are structs. However, the following will give you a vector of tforms.
clear tform_list
tform_list(max(X_dev))=rigidtform2d(); %pre-allocate
for i= X_dev
fl_c = fl(i); %Should probably be fl{i}
fu_c = fu(i); %Should probably be fu{i}
tform_list(i)= imregtform(fl_c,fu_c,'rigid',optimizer,metric);
end
save('tform_result.mat', 'tform_list');

3 个评论

oh, i forgot to attatch this part, actually, the fu_c is the readed image ('.IMG' file, and readed format is uint 16), and the fl_c is made image using 'affine transform'.
and there are some modified part of the code, and i attatched final code at the following.
clear tform_list
tform_list(max(X_dev))=rigidtform2d(); %pre-allocate
for i= X_dev
fl_c = fl(i); %Should probably be fl{i}
fu_c = fu(i); %Should probably be fu{i}
tform= imregtform(fl_c,fu_c,'rigid',optimizer,metric);
tform_list{i} = tform; % 1
tform_list(i)= imregtform(fl_c,fu_c,'rigid',optimizer,metric); % 2
end
save('tform_result.mat', 'tform_list');
And the tform result looks like this.
sorry for the the mistake. If this is the case, what should I do? thank you :)
Plus, actually, i want to save that 'tform_list', using 'save()'function, to .mat format, and want to load that 'tform_list' at another script.
when i save that tform_list, it works at the saving script, but when i loaded it and want to use the element of 'tform_list', the error like 'there is no field of T' was occured... :(
is this error occures because of the saving or loading routine? (not because of the saving to tform_list?)
thanks a lot :)
It doesn't change my answer, but you should read about cell arrays. Since you saved your results as a cell array, they will be a cell array when you load them back in, and need to be indexed the same way, with {}.
thanks a lot!! :))

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品

版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by