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

7 views (last 30 days)
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

Accepted Answer

Jan
Jan on 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.

More Answers (0)

Categories

Find more on Environment and Settings 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!