How to insert file name into an array?
조회 수: 7 (최근 30일)
이전 댓글 표시
I have a sequence of 62496 files. Each file name has information about height, year, month, day, hour and minute, for example, 14000_20140615_03000.dat
My script looks like the following:
clear all;
close all;
str='../Documents/';
folder_name = uigetdir(str);
files = dir(fullfile(folder_name,'*.dat'));
curr_folder=pwd;
cd(folder_name);
for i = 1: length(files);
fileID = fopen(files(i).name);
var = fread(fileID,[500 500], 'float32');
var20 = find(var>=20);
end
I want to create a matrix with the index of var20 and the height of this data, which is the information in the file name. That is, I need to obtain a matrix with two columns like this:
18582 14000
19647 14000
15824 14000
...
댓글 수: 0
답변 (1개)
dpb
2020년 8월 25일
str='../Documents/';
folder_name = uigetdir(str);
d=dir(fullfile(folder_name,'*.dat'));
for i = 1: length(files);
fid=fopen(fullfile(d(i).folder,d(i).name);
var = fread(fileID,[500 500], 'float32');
fid=fclose(fid);
var20 = find(var>=20);
ht=str2double(extractBefore(d(i).name,'_')); % get the height number from filename
heightArray=[repmat(ht,numel(var20),1) var20]; % create the new array
% either use these data here or save to new file or whatever before going on to next...
...
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!