Not able to create csv file using writetable after creating .exe file in Mac

조회 수: 4 (최근 30일)
I need to store outputs of my application to a .csv file. The *.fig file works fine and saves the outputs to the csv file as expected. But I when I use the application compiler and generate .exe file. The .exe file doesn't generate/ store the outputs to the csv file.
I was able to generate the expected outputs on windows fine. But when I did this on a Mac I am not able to get it.
I recreated my need here:
% --- Executes on button press in writeDat.
function writeDat_Callback(hObject, eventdata, handles)
% hObject handle to writeDat (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Names = ['NameX';'NameY';'NameZ'];
Sub1 = [23;33;43];
Sub2 = [53;63;73];
T = table(Names,Sub1,Sub2);
T.Properties.VariableNames = {'Name','Sub1','Sub2'};
try
writetable(T, fullfile(pwd,'trialTable.csv'));
msgbox('Sucess!');
catch
msgbox('Fail!');
end
This is the push button for example. It works fine as expected with .fig but not after creating .exe using application compiler.
Any suggestions?
  댓글 수: 6
Walter Roberson
Walter Roberson 2019년 4월 9일
Manual destination is one valid approach. Another valid approach is to uigetdir() or uiputfile() so the user can choose. A third valid approach is to examine the HOME environment variable to find the user's home directory (e.g., /Users/Gopichandh) and create the file in some location relative to that, such as
if ~ispc()
HOME = getenv('HOME');
apphome = fullfile(HOME, '.XXFolder');
else
HOME = getenv('APPDATA');
apphome = fullfile(HOME, 'XXFolder');
end
if ~exist(apphome, 'dir')
try
mkdir(apphome)
catch ME
error('Cannot create directory "%s", apphome');
end
end
filename = fullfile(apphome, 'TrialTable.csv');
Gopichandh Danala
Gopichandh Danala 2019년 4월 9일
편집: Gopichandh Danala 2019년 4월 9일
Thanks. The approach you explained using ispc, makedir is more dynamic and will be best fit for my requirement.
I think some others will have same issue as me in future. Post as an answer maybe. I will be accept so it helps others

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

채택된 답변

Walter Roberson
Walter Roberson 2019년 4월 9일
Manual destination is one valid approach. Another valid approach is to uigetdir() or uiputfile() so the user can choose. A third valid approach is to examine the HOME environment variable to find the user's home directory (e.g., /Users/Gopichandh) and create the file in some location relative to that, such as
if ~ispc()
HOME = getenv('HOME');
apphome = fullfile(HOME, '.XXFolder');
else
HOME = getenv('APPDATA');
apphome = fullfile(HOME, 'XXFolder');
end
if ~exist(apphome, 'dir')
try
mkdir(apphome)
catch ME
error('Cannot create directory "%s", apphome');
end
end
filename = fullfile(apphome, 'TrialTable.csv');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by