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
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