私は気象データセットを扱っており、多くの csv ファイルから 1 つの列を抽出し、結果を新しいファイルにコンパイルする必要があります。1 か月間は動作しましたが、それよりも短い月になるとスクリプトが動かなくなります (添字の割り当ての次元が一致しません)。理にかなっていますが、プレースホルダー行列 D に元々存在する NaN 値を単純に保持したいのです。
これがスクリプトの問題部分です、
%Convert dates to matlab date numbers and get number of rows
Date = datenum(Date{1, 1}, 'dd-mm-yyyy');
T = size(Date, 1);
%# Preallocate a matrix to hold all the data, and add the date column
D = [Date, NaN(T, NumFile)];
%# Loop over the csv files, get the eleventh column and add it to the data matrix
for k = 1:NumFile
FileList = dir('*.csv');
NumFile = size(FileList,1);
filename = FileList(k).name;
disp(filename);
%# Get the current file name
CurFilePath = filename;
%# Open the current file for reading and scan in the second column using numerical format
fid1 = fopen(CurFilePath, 'r');
CurData = textscan(fid1, '%*s %*s %*s %*s %*s %*s %*s %*s %f %*[^\n]', 'Delimiter', ',"', 'HeaderLines', 17, 'MultipleDelimsAsOne',true);
fclose(fid1);
%Add the current data to the cell array
D(:, k+1) = CurData{1, 1};
end
では、プレースホルダー行列 D に適合するように、短い月を 31 日月のサイズに強制するにはどうすればよいでしょうか。