Not able to create csv file using writetable after creating .exe file in Mac
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Gopichandh Danala
le 9 Avr 2019
Réponse apportée : Walter Roberson
le 9 Avr 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 commentaires
Walter Roberson
le 9 Avr 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');
Réponse acceptée
Walter Roberson
le 9 Avr 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Naming Conventions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!