用于创建循环的人物

1view (last 30 days)
本·史密斯
本·史密斯 2021年10月11日
评论: Mathieu Noe 2021年10月11日
I have created code which saves a bunch of files inside a folder of my main directory.
例如C:\ matlabstuff \ Work \ Data
我在工作中运行所有代码以及代码上半部分的数据在“数据”中。
我有一个由某人提供的代码
[infile,indir] = uigetfile('*.fid',,,,'选择文件');
FID=readSimpson([inDir,inFile]);
and ends with
Plotspectrum(Freq,SPE);
SHG
在介于两者之间的吸引力和其他东西。我希望尝试为此过程进行循环,以便我可以选择一个目录而不是单个文件,然后从数据中创建所有图形,并用名称'01xxxx.fig保存每个图形〜'30xxxx.fig'
I assume this will start with something like
fids = uigetdir('c:\ matlabstuff \ work'
info = dir(fullfile(fids,'*.fid'))
list = {info.name}
这将为我提供目录中的文件的峰值,以便我有循环的开始
为了i = 1:length(list)
此后,我有点迷失在这里。
For info 'FID' is processed into 'SPE' and FREQ is generrated based on SPE.

接受的答案

Mathieu Noe
Mathieu Noe 2021年10月11日
hello
请参阅下面的示例代码,以获取自然顺序的列表和排序文件名(MATLAB默认情况下的功能不佳)在给定文件夹中
在这里,我们加载多个Excel文件
hope it helps
fileDir = pwd;当前文件夹%
outfile ='out.xlsx';%输出文件名
fileNames = dir(fullfile(fileDir,'数据*.xlsx');% get list of data files in directory
fileNames_sorted = natsortfiles({fileNames.name});%将文件名分为订单(https://fr.mathworks.com/matlabcentral/fileexchange/47434-natural-order-order-filename-sort)
m =长度(filenames_sorted);
out_data = [];
为了f = 1:M
%选项#1仅使用ImportData的数字数据
raw = importData(fullfile(fileDir,fileNames_sorted {f}));
%的垂直contatenation所有个人文件ata
out_data = [out_data; raw.data];
结尾
% store out_data in excel file
writematrix(out_data,fullfile(filedir,outfile));
6 Comments
Mathieu Noe
Mathieu Noe 2021年10月11日
do :
filename = ['东西'num2str(i)];
savefig(文件名)

登录发表评论。

更多答案(0)

社区寻宝

在Matlab Central中找到宝藏,发现社区如何为您提供帮助!

Start Hunting!