How can I change in the directory while using dlmwrite?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 11 Mär. 2022
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)?
Antworten (1)
Jan
am 11 Mär. 2022
Bearbeitet: Jan
am 11 Mär. 2022
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 Kommentare
Siehe auch
Kategorien
Mehr zu Search Path finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!