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

3 Ansichten (letzte 30 Tage)
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 Kommentare
Walter Roberson
Walter Roberson am 9 Apr. 2019
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 am 9 Apr. 2019
Bearbeitet: Gopichandh Danala am 9 Apr. 2019
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 9 Apr. 2019
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');

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by