필터 지우기
필터 지우기

Problem in compiled app loading text, works in Matlab environment

조회 수: 1 (최근 30일)
Not sure what I'm doing wrong. This works fine when running in Matlab, but my compiled application throws an error:
"Error using textscan
Invalid file identifier. Use fopen to generate a valid file identifier."
The offending line is the last line in the code below. Thanks for any suggestions!
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
myfile=uigetfile('*.txt', 'Pick a Text file');
fid = fopen(myfile,'r'); %# Open the file
data = textscan(fid,'%s %s %s','CollectOutput',true); %# Read the data as strings

채택된 답변

Walter Roberson
Walter Roberson 2018년 5월 21일
[filename, filepath] = uigetfile('*.txt', 'Pick a Text file');
if ~ischar(filename); return; end %user cancel
myfile = fullfile(filepath, filename);
  댓글 수: 4
Walter Roberson
Walter Roberson 2018년 5월 21일
uigetfile never returns the directory information into the first output.
Compiled applications have quite different ideas of what the default directory should be on startup. This is not for "security": it is simply because executables started through the window manager are independent processes that have no idea what the "current" directory is in any other graphics process.
Jeremy Hughes
Jeremy Hughes 2018년 5월 22일
I only mean that the parameter filename may work without the full path information in MATLAB because the file was in the pwd or it could have been in some other folder that was added to MATLAB's path. Even in the compiled application, the user could have selected a file which is on the deployed app's MATLAB Path, and the original code would have opened it as expected.
Your solution is more robust in any case. =)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by