- So are you trying to save certain fields from a struct?
- Are you trying to convert a struct full of images into a volumetric or multiframe image and then save that to a .mat file?
- Are you trying to save a plain numeric array to a .mat file?
- Are you trying to separate the pages of a volumetric image into a bunch of new variables and then save them all to a .mat file?
How to concatenate/combine a list of images in one mat.file (convert picture 1 into picture 2)
3 次查看(过去 30 天)
显示 更早的评论
I tried a loop but it did not work:
for i = 1:size(df,3)
imshow(df(:,:,i))
end
3 个评论
回答(1 个)
Walter Roberson
2022-8-8
What you are asking for is possible but not recommended. You are asking to open the variable browser on each field of the struct, and have the header be the same as the field name. In order to do that it is necessary to extract the fields from the structure into individual variables that have the same name as the field names, as the command to open the variable browser only supports plain variable names, not field references.
The below code does that extraction, but first it makes sure that doing so would not overwrite any variable of the same name.
The code cannot be put into a function because any variable created would disappear as soon as the function returned. (Unless perhaps something could be done around global variables or persistent variables or base workspace.)
The code should be improved to check for conflicts with the variable names used to manage the loop. Oddly, that part could be put into a function.
F_E_I_L_D_S = fieldnames(df);
K_N_O_W_N = whos();
B_O_T_H_ = F_E_I_L_D_S(ismember(F_E_I_L_D_S, K_N_O_W_N));
if ~isempty(B_O_T_H_)
error('cannot view fields without interfering with existing variables: %s', strjoin(B_O_T_H_, ', ')) ;
end
for I_N_D_X_ = 1 : length(F_E_I_L_D_S)
T_H_I_S_ = F_E_I_L_D_S{I_N_D_X_};
eval( T_H_I_S_ + "= df."+T_H_I_S+";")
openvar(T_H_I_S_)
end
Creating variable names dynamically is seldom a good idea.
Note that the variable browser will allow you to edit the values, but the changes will not be written back to the struct.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!