我想循环下面的脚本,这样00001将依次增加(到00002,00003等等)。从1到100。00001出现了三次:在r5004b_00001.dat:%% Initialize variables和%% Allocate imported array to column variable names下:Angle00001和Intensity00001
%% Initialize variables.
filename = sprintf('E:\XRD\Enamel\r5004b_00001.dat');
startRow = 5;
%% Format string for each line of text:
formatSpec = '%14f%f%[^\n\r]';
%% Open the text file.
fileID = fopen(filename,'r');
%% Read columns of data according to format string.
dataArray = textscan(fileID, formatSpec, 'Delimiter', '', 'WhiteSpace', '', 'HeaderLines' ,startRow-1, 'ReturnOnError', false);
%% Close the text file.
fclose(fileID);
%% Allocate imported array to column variable names
Angle00001 = dataArray{:, 1};
Intensity00001 = dataArray{:, 2};
%% Clear temporary variables
clearvars filename startRow formatSpec fileID dataArray ans;发布于 2014-05-28 15:37:35
对于文件名,这是一个好主意,下面是解决方案(我只为清晰起见使用连接,sprintf当然足够了):
number = 3;
s = sprintf('%05d', number); % will produce '00003'
filename = ['E:\XRD\Enamel\r5004b_' s '.dat'];对于变量,别这么做。最好使用数组,或者,如果您真的喜欢有多个名称,则使用一个具有动态字段名的结构:
strct.(['angle' s]) = ...如果你真的想实现你想要的,可以用
eval(['a' s ' = 1 + 1;'])https://stackoverflow.com/questions/23915458
复制相似问题