directory created with num2str

10 ビュー (過去 30 日間)
Ribhu
Ribhu 2018 年 11 月 19 日
回答済み: Ribhu 2018 年 11 月 20 日
hi , I have created a folder using num2str.. but i can not save a file inside that directory as it shows error as "No such file or directory".
A=20; B=30; C=40;
xx=['A', num2str(A), 'B', num2str(B)] ;
mkdir(xx)
cfile= ['C', num2str(C)]
output2=[cfile,'.dat'];
save(['xx\', output2])

回答 (2 件)

madhan ravi
madhan ravi 2018 年 11 月 19 日
Try using sprintf()
  2 件のコメント
Ribhu
Ribhu 2018 年 11 月 19 日
it saves the file but does not save it nside the directory..
madhan ravi
madhan ravi 2018 年 11 月 19 日
specify the path correctly inside mkdir()

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


Ribhu
Ribhu 2018 年 11 月 20 日
I have tried using sprintf and fprintf.. but the problem is that the file is not saved inside the desired directory..
clear all
clc
U=2;
k=60;
Re=100;
sdp=['Re', num2str(Re)]
mkdir(sdp)
fnm = sprintf('U%s.dat', num2str(U));
save(fullfile(sdp,fnm), 'U')
fid2=fopen(fnm, 'w+');
fprintf(fid2,'U,k,Re\n');
fprintf(fid2,'%07.3f %07.3f %06.3f\n',U,k,Re);
fclose(fid2);

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by