using output of one button as an input in another button

8 ビュー (過去 30 日間)
ali hassan
ali hassan 2022 年 1 月 28 日
コメント済み: Rik 2022 年 1 月 28 日
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 件のコメント
DGM
DGM 2022 年 1 月 28 日
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.

サインインしてコメントする。

採用された回答

Rik
Rik 2022 年 1 月 28 日
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 件のコメント
Rik
Rik 2022 年 1 月 28 日
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 2022 年 1 月 28 日
[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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHistorical Contests についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by