save structures with fields in one .mat file

조회 수: 19 (최근 30일)
Eirik Kvernevik
Eirik Kvernevik 2021년 6월 9일
댓글: Eirik Kvernevik 2021년 6월 9일
I have n structures. Inside each of the n structures there are 6 fields and one struct array of size 20 each of them containing 2 fields
here is the code:
for i = 1:10
for j = 1:20
image_struct(i).reg(j) = registerImage(Moving,Fixed);
end
end
the image_struct(i) contains the following fields :
example with i = 1
>> image_struct_toID(1)
struct with fields:
name: 'image1'
original: [272×247×3 uint8]
IDnr: '000012'
Coord: [106 94]
circle_Radi: 43
circularimage: [87×87 double]
reg: [1×20 struct]
the structure array reg contains the following :using j = 1 as example :
>> image_struct_toID(1).reg(1)
struct with fields:
RegisteredImage: [87×87 double]
DisplacementField: [7656×2 double]
for each index i and j I want to save the resulting structures and fields in one . mat file , how can I do this ?
That is, I want everything stored in one .mat file
  댓글 수: 2
Stephen23
Stephen23 2021년 6월 9일
편집: Stephen23 2021년 6월 9일
"I want everything stored in one .mat file"
save('myfile.mat','image_struct')
Using indexing is the simplest and most efficient way to access the elements of a non-scalar structure.
Eirik Kvernevik
Eirik Kvernevik 2021년 6월 9일
thank you !
I also found out that if I want to store the structures while the for loops are running I can do this :
for i = 1:10
for j = 1:20
image_struct(i).reg(j) = registerImage(Moving,Fixed);
end
imageStruct.(sprintf('b%d',i)) = image_struct(i);
save('myfile.mat','-struct','ImageStruct');
end

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by