필터 지우기
필터 지우기

standalone(EXE) textscan is not working well

조회 수: 1 (최근 30일)
WoongLae Cho
WoongLae Cho 2024년 1월 5일
댓글: WoongLae Cho 2024년 1월 5일
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..

답변 (1개)

Walter Roberson
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
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.
WoongLae Cho
WoongLae Cho 2024년 1월 5일
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']);

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

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by