如何在Matlab中创建.mat文件? [英] How to create a .mat file in Matlab?
问题描述
我的文件夹中有25张图像,我想为路标识别系统制作一个 .mat 文件.
I have 25 images in a folder and I want to make a .mat file for a road-sign recognition system.
在Matlab中制作.mat文件的步骤是什么?
What are the steps for making a .mat file in Matlab?
推荐答案
对于图像可能有更好的方法,但这就是我所知道的.如果要控制 .mat 文件中的内容,则可以使用
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
这将创建文件 FileName.mat .
您可以使用 load
命令访问内容.
This creates a file FileName.mat.
You can access the contents using the load
command.
clear
load FileName
要将工作空间中的所有内容保存到 .mat 文件,请使用 save
命令,但未指定要保存的变量(MATLAB随后将全部保存).
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.
这需要您遍历文件夹中的图像.一种直接的方法是使用索引j
其中filepath = 'C:\Users\user1\Folder\ImageFolder\'
的[filepath 'image' num2str(j) '.jpg']
循环直接加载图像.这使用字符串连接和 num2str
命令.
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.
相关帖子:
使用matlab将多个图像存储在mat文件中
如何写入.mat文件matlab
Related Posts:
store multi images in mat file using matlab
how to write to .mat file matlab
这篇关于如何在Matlab中创建.mat文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!