standalone(EXE) textscan is not working well
1 次查看(过去 30 天)
显示 更早的评论
Hello. I want to make simple code as standalone(EXE).
1. Read text file
2. Sorting them
3. Save them to mat, txt or csv
Reading textfile works well in matlab. but whenever i deploy this to standalone, reading textfile returns broken data.
I made standalone using (MATLAB-APPS-Application Compiler) with same code.
filename = dir('Measurement*.asc');
copyfile(filename.name, [filename.name(1:end-4) '.txt']);
filename = fullfile(pwd, [filename.name(1:end-4) '.txt']);
fid = fopen(filename, 'r+');
rawdata1 = textscan(fid, '%s', 'Delimiter', '\n', 'MultipleDelimsAsOne', 1, 'headerlines', 3, 'TextType', 'string');
fclose(fid);
rawdata2 = readmatrix(filename, 'Numheaderlines', 3, 'ConsecutiveDelimitersRule', 'join', 'delimiter', ' ', 'OutputType', 'string');
save('TEST.mat');
Both rawdata1 and rawdata2 returns broken data... please help me..
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1582901/image.png)
0 个评论
回答(1 个)
Walter Roberson
2024-1-5
When you are using compiled executables, it is especially important to use fully qualified filenames everywhere.
filename = dir('Measurement*.asc');
No, you need to be specifying the directory name. See ctfroot or otherwise figure out where to read files from.
The default directory for files is not the user's "current" directory -- the program doesn't have any idea which directory is the "current" directory.
copyfile(filename.name, [filename.name(1:end-4) '.txt']);
Fully qualify!
oldname = fullfile(filename(1).folder, filename(1).name);
[olddir, basename] = fileparts(oldname);
newname = fullfile(olddir, [basename ".txt"]);
copyfile(oldname, newname);
5 个评论
Walter Roberson
2024-1-5
Getting the file names wrong can cause the problems you are seeing.
It is not worth debugging any further until after the filenames have been fixed to use absolute file names.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!