Parforループ内​で保存先のアドレスを​指定してdlmwri​teを使う方法

6 views (last 30 days)
O.E
O.E on 28 Feb 2018
Commented: O.E on 5 Mar 2018
Parforループを用いてシミュレーションを行い、dlmwriteを使ってCSVファイルに書き出して、その結果をそれぞれ別のフォルダに格納しようと考えています。方法が思いつかなかったため、それぞれ別の名前にして現在のディレクトリに保存した後にmovefileを用いてファイルを移動しているのですが、無駄が大きいので変更したいと考えています。どのようにすればよいでしょうか。
parfor i =1:length(j)
gain = j(1,i);
ditherfoldername = strcat('select','_',num2str(select),'_gain',num2str(gain));
mkdir(ditherfoldername);
[final]=Multi_OnebitlogPara(gain,select,dither_value);
nowname = strcat('adoutput',num2str(j(1,i)),'.csv');
movefile(nowname, ditherfoldername)
for f =1:4
if f == 3
else
nowname = strcat('adoutput',num2str(f),num2str(j(1,i)),'.csv');
movefile(nowname, ditherfoldername)
end
end
end
サブルーチンのプログラムの一部(入出力周り)
Ts =1;
a =gain;
bit = 1;
GAIN = dither_value;
q = 1/2^bit;
names = strcat('input.csv');
filename = names;
listing = dir(filename);
value = getfield(listing, 'bytes');
switch value
case 0
clear value
otherwise
clear value
IN=csvread(filename);
[Tsim,~] = size(IN);
IN_part = IN(1:Tsim,2);
IN_part2 = transpose(1:Tsim);
MAX = max(IN);
IN1 = [IN_part2 IN_part];
clear IN
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
IN_part(isnan(IN_part))=0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
IN1 = [IN_part2 IN_part];
clear IN_part2 IN_part n
[B] = simModel(a,Tsim,IN1,Ts,select,GAIN,q);
A = (1:MAX(1,1));
n=Tsim/MAX(1,1);
OUT1 = reshape(repmat(A,[1,n]),[Tsim,1]);
OUT = [OUT1 B];
clear A OUT1 B n
outnames = strcat('adoutput',num2str(gain),'.csv');
dlmwrite(outnames,OUT,'newline','pc');
clear OUT outname
end

Accepted Answer

Tohru Kikawada
Tohru Kikawada on 1 Mar 2018
詳細なプログラムの内容を理解できていませんが、 fullfile を使ってフォルダ名とファイル名を結合する方法はどうでしょうか。
修正前:
outnames = strcat('adoutput',num2str(gain),'.csv');
dlmwrite(outnames,OUT,'newline','pc');
修正後:
ditherfoldername = strcat('select','_',num2str(select),'_gain',num2str(gain));
outnames = strcat('adoutput',num2str(gain),'.csv');
dlmwrite(fullfile(ditherfoldername,outnames),OUT,'newline','pc');
  1 Comment
O.E
O.E on 5 Mar 2018
解決いたしました。
ありがとうございました。

Sign in to comment.

More Answers (0)

Categories

Find more on Parallel Computing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!