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

21 次查看(过去 30 天)
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

采纳的回答

Jan
Jan 2012-3-23
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.

更多回答(0 个)

类别

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