using output of one button as an input in another button

7 Ansichten (letzte 30 Tage)
ali hassan
ali hassan am 28 Jan. 2022
Kommentiert: Rik am 28 Jan. 2022
first i am using following command to get path and filename:
[filename,pathname] = uigetfile('*txt');
then i want to give these output (pathname and filename) as an input to another push button. how can i do so to link it?
  3 Kommentare
DGM
DGM am 28 Jan. 2022
How and whether it's practical depends entirely on how your code is structured and what you're trying to do. If you're trying to call another CBF directly without a button press, then you'd just pass it like you would any other function. If you're not trying to call the CBF directly, it probably wouldn't make sense to pass arguments directly like that.
I imagine most people might recommend using guidata, but I tend to use shared variables in GUI code.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Rik
Rik am 28 Jan. 2022
If you really want to, you can call the callback function like any other function.
However, it makes much more sense to only use buttons to call functions. There is no rule against two callbacks ending up calling the same function. Something like this:
function callback1(hObject,eventdata)
[filename,pathname] = uigetfile('*txt');
filename=fullfile(pathname,filename);
somefunction(filename)
end
function callback2(hObject,eventdata)
handles=guidata(hObject);
somefunction(handles.filename)
end
function somefunction(filename)
disp(fileread(filename))
end
As DGM mentions, there are several ways to share data between different parts of your GUI, using guidata or nested functions are only two. For general advice and examples for how to create a GUI (and avoid using GUIDE), have look at this thread.
  2 Kommentare
Rik
Rik am 28 Jan. 2022
Comment posted as answer by @ali hassan:
from open selected menu, i am running command:
[filename,pathname] = uigetfile('*.txt');
then i am using it in my function update button, but i want to know that how can i do so?
Rik
Rik am 28 Jan. 2022
[filename,app.pathname] = uigetfile('*.txt');
% ^^ that will probably work
You do need to make sure that openMenuSelected is called befor UpdateButtonPushed runs. You can do that fairly easily:
function UpdateButtonPushed(app,event)
%make sure the file path is selected
if isempty(app.pathname),UpdateButtonPushed(app,event),end
...
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Historical Contests finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by