Creating a counter loop in MatLab, GUI?
显示 更早的评论
Hello, i'm trying to create a loop counter that will add increments of 1 every time I click a pushbutton. I don't really have any code as of yet since i'm new to programming but i've figured how to detect the button being pushed, and display a number in the static text. It keeps displaying '1', how do I display 1,2,3,.....n for every push? Here is what I have so far. Thanks a bunch
a = 0;
if (handles.pushbutton5)
a = a + 1;
set(handles.text8,'string',a);
end;
3 个评论
Azzi Abdelmalek
2013-1-25
What "if true" is for?
Jan
2013-1-29
@Azzi: As Walter has explained before when I've asked the same question, the "if true, ..., end" appears, when you hit the "code" button when no text is selected.
Wouter
2013-11-7
And what if I want the option to count backwards?
I've tried creating a second pushbutton that produces:
counter = get(hObject, 'UserData') - 1;
However, no effect.
采纳的回答
更多回答(3 个)
Azzi Abdelmalek
2013-1-25
set(handles.text8,'string',num2str(a));
5 个评论
Azzi Abdelmalek
2013-1-25
编辑:Azzi Abdelmalek
2013-1-25
Because every time you have
a=0
Use
a=str2double(get(handles.text8,'string'))
instead of
a=0
Azzi Abdelmalek
2013-1-25
Look at the above code
Azzi Abdelmalek
2013-1-25
In opening function initialize
Set(handles.text8,'string','0')
1 个评论
Azzi Abdelmalek
2013-1-29
编辑:Azzi Abdelmalek
2013-1-29
The initialization is not in the right place. You should do it in your opening function, not in your pushbutton function
类别
在 帮助中心 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!