Filter löschen
Filter löschen

standalone(EXE) textscan is not working well

1 Ansicht (letzte 30 Tage)
WoongLae Cho
WoongLae Cho am 5 Jan. 2024
Kommentiert: WoongLae Cho am 5 Jan. 2024
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..

Antworten (1)

Walter Roberson
Walter Roberson am 5 Jan. 2024
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 Kommentare
Walter Roberson
Walter Roberson am 5 Jan. 2024
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.
WoongLae Cho
WoongLae Cho am 5 Jan. 2024
There is a part saving variables to file.
when i open it, the filename is fine, it is in the proper path.
and i tried below code to give EXE proper path. but getting same wrong textscan data.
if isdeployed
[status, result] = system('path');
installpath = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));
else
installpath = pwd;
end
filename = dir('Measurement*.asc');
copyfile(fullfile(installpath, filename.name), [fullfile(installpath, filename.name(1:end-4)) '.txt']);
filename = fullfile(installpath, [filename.name(1:end-4) '.txt']);

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by