Standalone (compiled) program reading external files

Hi,
I currently have a program running in Matlab that uses 'textscan' to read several .csv files located in the same directory as the main program and use the data it obtains from them.
When I export this as a standalone program using the Matlab Compiler I have to include these files within the "shell" of the application. Is there a way getting a compiled program to read files stored within its directory (as the "pre compiled" version did) such that when they are updated with new data the program uses this updated data?
(This is necessary as my end users need access to these csv files but do not have Matlab).
Thanks in advance.

댓글 수: 4

José-Luis
José-Luis 2014년 6월 24일
편집: José-Luis 2014년 6월 24일
I am not sure I totally understand the problem, but isn't this something that could be solved by passing the absolute path of the files to textscan()?
doc pwd
doc fullfile
Thanks for the swift reply.
That does sound logical.
Basically when you use deploytool to compile the program it asks you to add any data or function files to the "shared resources and helper files". I want to have a standalone program that doesn't include any of my data files within this section and can read them separately as my original code does when run it in Matlab. Does that make more sense?
The textscan section of my code is below;
filename = 'MASTER.csv'; fid = fopen(filename); T = textscan(fid, '%s%s%s%s%s%f%f%f%f%f%f','Delimiter',',','headerlines',1,'TreatAsEmpty', '#DIV/0!'); fclose(fid);
How would you suggest I alter it if you still think that solution would work?
Cheers
filename = 'MASTER.csv';
fid = fopen(filename);
T = textscan(fid, '%s%s%s%s%s%f%f%f%f%f%f','Delimiter',',','headerlines',1,'TreatAsEmpty', '#DIV/0!');
fclose(fid);
ahh realise those pwd and fullfile were links to help files. (Question still stands though).

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

 채택된 답변

José-Luis
José-Luis 2014년 6월 24일
Maybe something like this:
filename = fullfile('/path/to/files','MASTER.csv');
fid = fopen(filename)

댓글 수: 3

cheers, yeh used your suggestion of;
direc = pwd; filename = fullfile(direc,'MASTER.csv');
will publish result
José-Luis
José-Luis 2014년 6월 24일
편집: José-Luis 2014년 6월 24일
Please accept the answer that best solves your problem.
direc = pwd
is redundant. You could do:
filename = fullfile(pwd,'MASTER.csv');
But even then, I don't really follow. If the files are in the working directory, you shouldn't need give the full path.
yep thats a good'un

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

추가 답변 (1개)

Titus Edelhofer
Titus Edelhofer 2014년 6월 24일
Hi,
I'm not sure I fully understood the question. If you don't add the MASTER.csv during compilation, and have a call to fopen, then fopen will look in the current folder (which is the folder where the executable is). So if you have in one folder both the .csv and the yourprogram.exe, then everything should be fine ...?
If not, add a line
p = pwd
to find out, "where" you are when running the compiled application.
Titus

카테고리

도움말 센터File Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

질문:

2014년 6월 24일

댓글:

2014년 6월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by