Using an external function in GUI closes the interface

Hello!
I am using an external function I made outside GUI (heart_rate.m) and I am using it in a push button in GUI. The problem is that every time I press the button, the functions runs and returns the value I want, but after the interface just closes by itself.
At the moment the code is something really basic like this:
function pushbutton_connect_Callback(hObject, eventdata, handles)
(..)
global HR;
HR = heart_rate(data1,sr);
msgbox(sprintf('Your heart rate is: %3.f', HR));
The msgbox appears and shows the correct number for data1, but then the thing just closes. I have also used a different external function just to test and the behaviour is the same.
Any idea on what is the problem? I am relatively new to guide, so I apologize in advance for any mistakes I may say :)

3 件のコメント

Sara
Sara 2014 年 7 月 16 日
What's the code after the one you have posted? Try putting a breakpoint on the msgbox line and look at what happens when you proceed step by step.
Joseph Cheng
Joseph Cheng 2014 年 7 月 16 日
the whole gui closes? or just the msg box?
Inês
Inês 2014 年 7 月 17 日
編集済み: Inês 2014 年 7 月 17 日
The whole gui closes. For this function there is only this portion of code, and its not connected with to any other function on gui as I am still testing it.
I narrowed to problem to the line where I call the function heart_rate. If I run the code without calling the function (i.e. comment that line) the message box appears and nothing closes. Otherwise when I run without the msgbox the interface closes down again.
If it helps, the function heart_rate is this one: heart_rate

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

 採用された回答

Geoff Hayes
Geoff Hayes 2014 年 7 月 17 日

0 投票

The heart_rate function, if like that in the above link, has as its first line
close all; clc;clear all;
Calling close all would close the GUI yet still allow the message box to display. Try removing this line and re-running the application.

1 件のコメント

Inês
Inês 2014 年 7 月 17 日
編集済み: Inês 2014 年 7 月 17 日
I forgot to mention that I had deleted that line to avoid such an error. Unfortunately the GUI still closes and no error is displayed :\
EDIT: just understood what the problem was. I edited heart_rate from the link and included some children functions, one of which had close all. Now it'a running.
Thanks Geoff! What a dumb mistake :)

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

その他の回答 (0 件)

カテゴリ

質問済み:

2014 年 7 月 16 日

編集済み:

2014 年 7 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by