how to write file in userdefined directors using fopen/fwrite/fclose

21 vues (au cours des 30 derniers jours)
Rami
Rami le 23 Mar 2012
Hi, I want to write file in user defined folder but not in matlab current directory. I tried to use following commands but no success, still writing into current matlab directory
P1=path;
path(P1,'C:\MATLAB701\work\user_defined');
files_out = dir(fullfile(matlabroot,'\work\user_defined/*.dat'));
filename = files_out(1).name;
outid = fopen(filename,'w+');
fwrite(outid,imagedata,'uint16');
fclose(outid);
Any help will be appreciable. Thanks, Rami

Réponse acceptée

Jan
Jan le 23 Mar 2012
The dir command replies the file names without the path.
There is no need to add the folder to the path. Better:
folder = fullfile(matlabroot, '\work\user_defined\');
files_out = dir(fullfile(folder, '*.dat'));
filename = files_out(1).name;
disp(filename); % Show the filename
outid = fopen(fullfile(folder, filename), 'w+');
fwrite(outid,imagedata,'uint16');
fclose(outid);
A general method to investigate such problems is the debugger. Set a break point inthe editor to the line, which behaves unexpectedly. Then Matlab stops at this break point and you can check the values of the variables in the command window.
  1 commentaire
Rami
Rami le 26 Mar 2012
Jan,
Thanks a lot for providing the commands and useful suggestion. Rami

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Search Path dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by