There may be a better approach for images but here is what I know. If you want to control what goes into the .mat file you can specify what variables in your workspace will be saved using the save command.
% MATLAB R2017a
X = rand(273,273);
Y = rand(273,273);
Z = rand(273,273);
save FileName X Y Z
This creates a file FileName.mat.
You can access the contents using the load command.
clear
load FileName
To save everything in the workspace to a .mat file, use the save command without specifying the variables to save (MATLAB will then save them all).
W = rand(273,273);
save FileName
See the linked documentation for more options and examples.
This requires you to loop through the images in the folder. A direct approach to this is directly loading the images using a loop over [filepath 'image' num2str(j) '.jpg']
with index j
where filepath = 'C:\Users\user1\Folder\ImageFolder\'
. This uses string concatenation and the num2str command.
If you need to change your current directory within the script,the cd function is useful.
Related Posts:
store multi images in mat file using matlab
how to write to .mat file matlab