Read file, extract region and save
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to read multiple .nc files (I know how to do this, see below), then extract a small region from each file (not familiar how to do this), save this region in a matrix (3D), close file and repeat this again, through all 37 (years) .nc files, in a loop. Each file size is 1440 x 720 x ## (Longitude x Latitude x TimeStep), where ## are the number of days (could go from 120 to 366), depending of year (first and last year have less days, and there are leap and non-leap years).
myFolder = 'C:\Data';
filePattern = fullfile(myFolder, '*.nc');
matFiles = dir(filePattern);
for k = 1:length(matFiles), %length(matFiles)=37
baseFileName = matFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
Data(:,:,k) = ncread(fullFileName,'VariableName');
end
I am missing the portion of how to extract a small region from each .nc file inside loop, and then how to add it (using cat function ?) to generate a 3D matrix with each TimeStep (day) from each of the 37 files.
Your comments and suggestions are welcome. Thanks!
2 个评论
Image Analyst
2017-4-18
We don't know how the regions are to be identified. Do you want to hand-trace them? Do you want them identified by thresholding? I have no idea. Are the regions all rectangles of the same size? They'd better be if you want to concatenate them into a 3-D array. Maybe you could attach one of the files, or at least show us a screenshot of what they look like.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!