standalone(EXE) textscan is not working well
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Walter Roberson
il 5 Gen 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 Commenti
Walter Roberson
il 5 Gen 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.
Vedere anche
Categorie
Scopri di più su Text Files in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!