How can I change in the directory while using dlmwrite?

2 ビュー (過去 30 日間)
Sahar khalili
Sahar khalili 2022 年 3 月 11 日
編集済み: Walter Roberson 2022 年 3 月 11 日
Hi
I have a problem, I use dlmwrite to write data in a excel file, but when I run the code, I have noticed that the directory in which lake_para_file is addressed does not exist at al.
lake_par_file = tempname;
fid=fopen(lake_par_file,'wt');
fprintf(fid,'\n\n');
dlmwrite(lake_par_file, [[1:length(K_lake)]',data_lake{2},data_lake{3},data_lake{4},(1:length(K_lake))'],'delimiter','\t','-append'); % 1:length(K_lake) is the length of the parameter file.
fclose(fid);
Does anybody know how can I change the directory?
  3 件のコメント
Sahar khalili
Sahar khalili 2022 年 3 月 11 日
no it says true. But I cannot find such directory that it is addressed in the workspace.

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

回答 (1 件)

Jan
Jan 2022 年 3 月 11 日
編集済み: Jan 2022 年 3 月 11 日
I do not understand, what the problem is. The function tempname creates a file in your TEMP folder. Under Windows this is: C:\Users\<YourAccount>\AppData\Local\Temp\ . The file name is chosen randomly, e.g. 'tp3ed79371_4d80_4861_aa70_9b2bf68b293c' without a file extension.
What does "addressed in the workspace" mean?
Why do you open the file in addition by:
fid=fopen(lake_par_file,'wt');
"Does anybody know how can I change the directory?" - which one? The cd command changes the current directory, but this is a fragile method to determine the output folder. Prefer to use an absolute file name instead, e.g.
Folder = cd; % Or 'C:\Temp' or which folder you prefer
File = 'myData.csv';
dlmwrite(fullfile(Folder, File), ...
[(1:length(K_lake)).', data_lake{2:4, (1:length(K_lake)).'], ...
'delimiter', '\t', '-append');

カテゴリ

Find more on Instrument Connection and Communication 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!

Translated by