How can I change in the directory while using dlmwrite?

3 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2022-3-11
I am not clear on what you mean about the directory. Are you saying that if you
td = fileparts(lake_par_file)
isfolder(td)
will say false (0)?
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');

类别

Help CenterFile Exchange 中查找有关 Search Path 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by