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

조회 수: 21 (최근 30일)
Rami
Rami 2012년 3월 23일
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.
  댓글 수: 1
Rami
Rami 2012년 3월 26일
Jan,
Thanks a lot for providing the commands and useful suggestion. Rami

댓글을 달려면 로그인하십시오.

추가 답변 (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