Possible Codes for GUI pushbutton!!!

i will like a button on my GUI when clicked on, to run and exe file in folder on my computer. Please can anyone help me with possible codes to use so my button can perform this task?

 Risposta accettata

Walter Roberson
Walter Roberson il 6 Giu 2018
Modificato: Walter Roberson il 6 Giu 2018
function pushbutton1_Callback(hObject, event, handles)
filedir = pwd;
exedir = pwd; %not necessarily the same as where files are
exename = 'gusprime.exe';
exefullname = fullfile(exedir, exename);
fileinfo = dir(fullfile(filedir, '*.dat'));
filenames = fullfile(filedir, {fileinfo.name});
numfiles = length(filenames);
for K = 1 : numfiles
thisfile = filenames{K};
cmd = sprintf('"%s" /some /options /here "%s"', exefullname, thisfile);
[status, message] = system(cmd);
if status == 0
fprintf('Okay processing file "%s"\n', thisfile);
else
fprintf('Error processing file "%s", message was "%s"\n', thisfile, message);
end
end

4 Commenti

Thanks for your respond but im a little new to matlab so im not sure of the changes i have to make on your codes to fit mine. The only thing i change so far is the line exename = 'gusprime.exe'; to exename = 'pfMainL.exe'; since my exe file name is pfMainL.
Actually that could already be enough, though you maybe do not want a loop. If you only want to run your .exe you need only a few lines of Walters Code.
function pushbutton1_Callback(hObject, event, handles)
exedir = pwd; %pwd gets your current directory, if needed replace with 'C:\Users\....wherever your .exe is
exename = 'pfMainL.exe';
exefullname = fullfile(exedir, exename);
[status, message] = system(exefullname);
end
Thanks Denis, that was very helpful but i realized my gui button only runs this exe file when the exe file's folder is open on the current folder pannel. My next question is, how can i set my gui button to always run this exe file no matter if its the exe file's folder open in the current folder pannel or Not.
What does it mean for the exe file's folder to be open to something? Are you trying to connect to and run a program that is already running?
When you run pfMainL for a particular file, what would you type on the command line if you were doing it by hand?
I am having difficulty finding pfMainL.exe on the internet to find documentation about it?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su App Building in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by