How can I change in the directory while using dlmwrite?
4 次查看(过去 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
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)?
回答(1 个)
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');
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Search Path 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!