필터 지우기
필터 지우기

Problem using for loop

조회 수: 1 (최근 30일)
Sophia
Sophia 2017년 4월 27일
편집: per isakson 2017년 4월 29일
clear all;clc;
% load OSI_SAF_OSI401_10km_geoloc_area.mat
% path to data directory
folderpath = 'C:\Users\SK\Documents\MATLAB\SIC_data\OSISAF_401b\';
for m = 7:9;
if m==7
datapath = '2007\07\';
elseif m==8
datapath = '2007\08\';
elseif m==9
datapath = '2007\09\';
end
% make list of files in selected folder
files = dir( fullfile(folderpath,datapath,'ice_conc_nh_2*.hdf') );
files = {files.name}';
%
dd = [];
%
% go through all files and add into datamatrix dcube
for ii=1:numel(files)
%
disp(files{ii}); % show filename on screen to follow progress
filename = fullfile(folderpath,datapath,files{ii}); % full path to file
%
d = h5read(filename,'/Data/data[00]'); % read data
h = h5read(filename,'/Header'); % read header with d/m/y information
%
d = reshape(d,760,1120);
d(d==-99)=NaN;
d(d<0)=NaN;
%
dd(:,:,ii) = d;
end
sic_mnth(:,:,3) = nanmean(dd,3);
% if i put m instead i get the result but i don't want the
% sic_mnth to be (:,:,9) size
end
%
load lat_long.mat;
figure(200707);
clf; hold on;
m_proj('stereographic','lat',90,'long',0,'radius',33);
% levels = [0 15 50 70 85 90 100];
[c,h]=m_contourf(long,lat,sic_mnth(:,:,1),'linestyle','none');
m_coast('patch',[.6 .6 .6]);
m_grid('linewi',2,'tickdir','out');
caxis([0 100]);
colorbar;
If i run it for a single file it is working, the problem is with using the for loop but could not find how to fix it
for m = 7:9;
if m==7
datapath = '2007\07\';
else
end
% make list of files in selected folder
files = dir( fullfile(folderpath,datapath,'ice_conc_nh_2*.hdf') );
files = {files.name}';
%
dd = [];
%
% go through all files and add into datamatrix dcube
for ii=1:numel(files)
%
disp(files{ii}); % show filename on screen to follow progress
filename = fullfile(folderpath,datapath,files{ii}); % full path to file
%
d = h5read(filename,'/Data/data[00]'); % read data
h = h5read(filename,'/Header'); % read header with d/m/y information
%
d = reshape(d,760,1120);
d(d==-99)=NaN;
d(d<0)=NaN;
%
dd(:,:,ii) = d;
end
sic_mnth(:,:) = nanmean(dd,3);
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by