help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

User Interface Application using GNU Octave 4.0, possible?


From: YX Boon
Subject: User Interface Application using GNU Octave 4.0, possible?
Date: Thu, 18 Feb 2016 11:38:56 +0800

Hello there,

I am trying to implement a User Interface application, where the application can perform certain calculation after all the entered values, and computed results are changed according to a sliding value (based on a slider). Then some plots can be generated.

I know MATLAB can do this. However, when I try with GNU Octave 4.0, my UI could not be updated after the callback function (either perform calculation or display certain character).

My codes are as below: (a simple 4 functions calculator)

function gui_calculator_4function
% gui_calculator has 2 edit boxes for numbers and
% adds, subtracts, multiplies or divides them
Fig = figure ('Position', [100 100 1000 600]);
set(Fig, 'Name', 'GUI Calculator')
n1 = 0; n2 = 0;
title = uicontrol('Style', 'text', 'Position', [150,400,700,100],...
'FontSize', 20, 'String', 'Four Function Calculator');
operator = uicontrol('Style', 'text', ...
'Position', [240,300,50,60], 'FontSize',  10);
equal_sign = uicontrol('Style','text',...
'Position',[540,300,50,60],'FontSize', 10,'String','=');
result = uicontrol('Style','text',...
'Position',[600,300,300,60]);
firstnum = uicontrol('Style','edit','Position',[20,300,200,60],...
'FontSize', 20, 'String',num2str(n1));
secondnum = uicontrol('Style','edit','Position',[320,300,200,60],...
'FontSize', 20,'String',num2str(n2));
add_button = uicontrol('Style','pushbutton', 'String','Add',...        
'Position',[80,50,100,50], 'Callback',@callbackfn);
subtract_button= uicontrol('Style','pushbutton', 'String','Subtract',...           
'Position',[200,50,100,50], 'Callback',@callbackfn);
multiply_button = uicontrol('Style','pushbutton', 'String','Multiply',...      
'Position',[320,50,100,50], 'Callback',@callbackfn);
divide_button = uicontrol('Style','pushbutton', 'String','Divide',...       
'Position',[440,50,100,50], 'Callback',@callbackfn);
end

function callbackfn(source,eventdata)
   display(firstnum)
   n1 = str2num(get(firstnum,'String'))
   n2 = str2num(get(secondnum,'String'))
   if source == add_button
   op ='+';  
   answer = n1 + n2;
   elseif source == subtract_button
   op ='-'; 
   answer = n1 - n2;
   elseif source == multiply_button
   op ='*'; 
   answer = n1 * n2;
   elseif source == divide_button
   op ='/'; 
   answer = n1 / n2;
   end
  operator1 = uicontrol('Style', 'text', ...
  'Position', [240,300,50,60], 'String', op, 'FontSize',  10);
  %set(operator,'String',op,'FontSize',10)
  result1 = uicontrol('Style','text',...
  'Position',[600,300,300,60], 'String', num2str(answer), 'FontSize', 10);
  %set(result,'String',num2str(answer),'FontSize',20)
end 

My question is does Octave 4.0 support the UI application that I would like to implement?
I could not find how should I do so.

Hope to hear from you soon!

Have a great day!

Best Regards,
Yinn Xi

reply via email to

[Prev in Thread] Current Thread [Next in Thread]