For stand-alone exe, how do I include a folder of files and know how to access them.
조회 수: 13 (최근 30일)
이전 댓글 표시
I have a folder of files I have added to a stand-alone exe. I have been using Desktop->WindowsStandAloneApplication -> Build. There is a link to add files or directories. I have added a folder which has my data files. However, I don't know how to access them. I have tried
if isdeployed
mydir = ctfroot ;
myfile = 'myfile.dat';
fid=fopen([mydir, myfile]);
else
...
end
but it doesn't find the file.
댓글 수: 0
채택된 답변
Friedrich
2013년 1월 18일
편집: Friedrich
2013년 1월 18일
Hi,
everything you add to your project will keep the same folder hierachy. So lets say you have a folder called myfolder and in there a file called myfile.dat. Then you would need to do:
if isdeployed
fid = fopen(fullfile(ctfroot,'myfolder','myfile.dat'))
end
You can also compile once and not embed the CTF. After compilation, open the ctf file in some zip programm and take a look at the folder structure.
추가 답변 (2개)
owr
2013년 1월 18일
When you concatenate strings using "[...]" the way you wrote above you are missing the "\" between the file name and path (on Windows at least):
mydir = ctfroot ;
myfile = 'myfile.dat';
[mydir, myfile]
ans =
C:\Program Files\MATLAB\R2012amyfile.dat
This would work better:
mydir = ctfroot ;
myfile = 'myfile.dat';
[mydir,'\',myfile]
ans =
C:\Program Files\MATLAB\R2012a\myfile.dat
But Friedrich's suggestion above to use "fullfile" is a cleaner more robust solution to accomplish the same thing.
댓글 수: 0
sara selim
2015년 5월 24일
Hi , i have the same problem i tried alot of solution but all of them were wrong , can you tell me how you have solved your problem ?
댓글 수: 1
Walter Roberson
2015년 5월 24일
sara, we are expecting you to reply to your existing question http://uk.mathworks.com/matlabcentral/answers/218321-cd-statment-and-connection-from-matlab-to-c . You should post your current ctfroot-using code there.
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Compiler에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!