Not able to create csv file using writetable after creating .exe file in Mac
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gopichandh Danala
am 9 Apr. 2019
Beantwortet: Walter Roberson
am 9 Apr. 2019
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
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');
Akzeptierte Antwort
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');
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Naming Conventions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!