Having trouble compiling importdata

조회 수: 2 (최근 30일)
Kilian Weber
Kilian Weber 2017년 6월 22일
답변: Aylin 2017년 6월 26일
I finished a long Matlab code, that works just perfect in Matlab. Now I'm trying to compile the app, to use it as an .exe file on other computers.
relevant code:
[FileName,PathName] = uigetfile('*.CSV','Select the data file');
delimiterIn = ',';
headerlinesIn = 11;
A = importdata(FileName,delimiterIn,headerlinesIn); % A becomes a 1x1 struct containing data, textdata and colheaders
the code imports a .CSV file.
The uigetfile works just fine, as I used [FileName,PathName]. But at line 4 A |= importdata(FileName,delimiterIn,headerlinesIn);|the code stops working an I get the following Error message:
> Unable to open File.
> Error in => name_of_my_program.m line 4
Any ideas how to solve this problem? I can't change much in the code, as the varibales A.data and A.headliners are used a lot in the code.
Did I use the `importdata` function wrong? Does the importdata function not work with compiled apps?
csvread istead of importdata does work, but as mentioned above, I'm looking for a solution, were I don't need to change all the variables in my long code. So the output got to be a 1x1 struct containing A.data, A.textdata and A.colheaders
I use MATLAB R2017a and the Appliaction Compiler within
This question is relatrd but doesn't deal with importdata issues.

채택된 답변

Aylin
Aylin 2017년 6월 26일
From the previous MATLAB Answers post which you linked, it seems like it might be important to provide importdata with the full path to the file from uigetfile. You can try combining the FileName and PathName parameters from uigetfile using the fullfile function:
[FileName,PathName] = uigetfile('*.CSV','Select the data file');
fullFilePath = fullfile(PathName, FileName);
delimiterIn = ',';
headerlinesIn = 11;
A = importdata(fullFilePath,delimiterIn,headerlinesIn);
See the fullfile documentation page for more information: https://www.mathworks.com/help/matlab/ref/fullfile.html

추가 답변 (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