フィルターのクリア

my code is not running

1 回表示 (過去 30 日間)
Seemant Tiwari
Seemant Tiwari 2021 年 8 月 12 日
回答済み: Image Analyst 2021 年 8 月 12 日
for year = 2009:2017
year index = year-2008
year struct = load( [ 'D:\DataStation\hr ',num2str(ye), '\mat\station.mat' ] );
for station = 1:30
eval ( [ "station double = year struct.station_',num2str(station),';'] );
station double = station double (1:8760,:);
data(:,:,station,year) = station double
end
end

採用された回答

Chunru
Chunru 2021 年 8 月 12 日
編集済み: Chunru 2021 年 8 月 12 日
This is my best guess.
for year = 2009:2017
year_index = year-2008 % no space in variable names
year_struct = load( [ 'D:\DataStation\hr ',num2str(year), '\mat\station.mat' ] );
for station = 1:30
eval ( ['station_double = year_struct.station_', num2str(station), ';'] );
station_double = station_double (1:8760,:);
data(:, :, station, year_index) = station_double;
end
end

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 8 月 12 日
This is how I'd do it:
for theYear = 2009:2017
yearIndex = theYear-2008; % no space in variable names
fullFileName = sprintf('D:/DataStation/hr %d/mat/station.mat', theYear);
if isfile(fullFileName)
% Load .mat file into a structure.
yearStruct = load(fullFileName);
% Get all the field names 'station_1', 'station_2', etc. into a cell array
fn = fieldnames(yearStruct);
for station = 1 : length(fn)
% Get this particular field name.
thisFieldName = fn{station};
% Get the 2-D array in this field.
thisMatrix = yearStruct.(thisFieldName);
% Crop out part of it.
station_double = thisMatrix (1:8760,:);
% Add this matrix to our 4-D array.
data(:, :, station, yearIndex) = station_double;
end
else
warningMessage = sprintf('Warning: file not found:\n%s', fullFileName);
uiwait(warndlg(warningMessage));
end
end

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by