フィルターのクリア

Create subfolders in the desired way

2 ビュー (過去 30 日間)
Daphne PARLIARI
Daphne PARLIARI 2020 年 1 月 14 日
コメント済み: Daphne PARLIARI 2020 年 1 月 14 日
Hi community! I would appreciate your contribution to the following.
I have created the directory I want (the first of which is C:\Users\dparliari\Desktop\OutputEv\Airport\Temperature) using the following lines:
output_path='C:\Users\dparliari\Desktop\OutputEv'
vars={'Temperature'; 'Relative humidity'};
for m=1:size(vars,1)
if(~exist([output_path,'\',namestr,'\',strrep(vars{m},' ','_'),'\'],'dir'))
mkdir([output_path,'\',namestr,'\',strrep(vars{m},' ','_'),'\'],'dir')
end
end
Now I want to create a subfolder based on the year in this way: C:\Users\dparliari\Desktop\OutputEv\Airport\Temperature\2015
I guess it must be something like:
output_path='C:\Users\dparliari\Desktop\OutputEv'
vars={'Temperature'; 'Relative humidity'};
years = {'2015'; '2019'};
for m=1:size(vars,1)
if(~exist([output_path,'\',namestr,'\',strrep(vars{m},' ','_'),'\'],'dir'))
mkdir([output_path,'\',namestr,'\',strrep(vars{m},' ','_'),'\'],'dir')
for k = 1:size(years,1)
if(~exist([I HAVE NO IDEA!!))
mkdir([ALSO NO IDEA!!)
end
end
end
Any ideas please??
  2 件のコメント
per isakson
per isakson 2020 年 1 月 14 日
Use fullfile, Build full file name from parts that makes the code more robust and readable.
Daphne PARLIARI
Daphne PARLIARI 2020 年 1 月 14 日
Sorry I didn't get it. Can you please explain a bit further?

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2020 年 1 月 14 日
編集済み: Guillaume 2020 年 1 月 14 日
As Per isakson said, use fullfile instead of building paths manually. fullfile automatically inserts the correct path separator for whichever OS your code is running on.
I would do it like this
output_path='C:\Users\dparliari\Desktop\OutputEv';
vars={'Temperature'; 'Relative humidity'};
years = {'2015'; '2019'};
[vv, yy] = ndgrid(vars, years); %note that this syntax is not officially supported. If it's a problem use
%[vv, yy] = ndgrid(1:numel(vars), 1:numel(years)); vv = vars(vv); yy = years(yy);
allfolders = fullfile(output_path, 'Airport', vv, yy);
for fidx = 1:numel(allfolders)
if ~exist(allfolders{fidx}, 'dir')
mkdir(allfolders{fidx});
end
end
  3 件のコメント
Guillaume
Guillaume 2020 年 1 月 14 日
First, you need to learn to use tables properly.
stations(x, y)
uses () indexing and thus returns a table (the portion of the table referenced by indices x, y.
stations{x, y}
uses {} indexing and thus returns the content of the table.
Another way to get the content is with . indexing:
stations.y(x)
So, instead of:
network = stations (i, 'Network');
% ...
networkstr = char(network.(1));
simply:
networkstr = char(stations{i, 'Network'});
or
networkstr = char(stations.Network(i)); %probably simpler
I'm not convinced the char() conversion is even needed.
So I can understand better what your code is doing, can you attach an example input table?
Daphne PARLIARI
Daphne PARLIARI 2020 年 1 月 14 日
I am attaching the list of stations and an example of data (excel file).
Plus you are correct, line
networkstr = char(network.(1));
works exactly as
networkstr = char(stations{i, 'Network'});

サインインしてコメントする。

その他の回答 (1 件)

per isakson
per isakson 2020 年 1 月 14 日
編集済み: per isakson 2020 年 1 月 14 日
Try this
%%
output_path = 'd:\m\cssm'; % 'C:\Users\dparliari\Desktop\OutputEv'
vars = {'Temperature', 'Relative_humidity'};
years = {'2015', '2019'};
for vv = vars
for yy = years
ffs = fullfile( output_path, 'Airport', vv{:}, yy{:} );
mkdir( ffs );
end
end
  1 件のコメント
per isakson
per isakson 2020 年 1 月 14 日
Should be 'Airport' not Airport

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by