Callback error and creation of callback

Hi,
I have a problem I create a GIU. And I have 4 buttons. Each callback should work with different equation comming from outside. How I should write it? Please, help me!
Capture1.PNG

5 Comments

The question is not clear yet. What does "coming from outside" mean? What exactly is "each callback work with an equation"?
What is the purpose of calculate here? Where does the input a come from? What should happen with the output of the functions?
Please post the code as text, not as screenshot, such that we can use it to post an answer.
function varargout = untitled(varargin)
% UNTITLED MATLAB code for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or raises the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input arguments.
%
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help untitled
% Last Modified by GUIDE v2.5 26-May-2019 13:29:18
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before untitled is made visible.
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to untitled (see VARARGIN)
% Choose default command line output for untitled
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes untitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles=guidata(hObject);
calculate myfunctionac;
guidata=(hObject)
function Sac=myfunctionac(RA,a)
Sac=(RA*2*38.8^3)/(2*38.8^3+3*38.8*a+a^3)*(38.8-a)^2/(2*38.8^3)*(2*38.8+a)
end
function [Sbc]=myfunctionsbc(RA,a)
Sbc=-((RA*2*38.8^3)/(2*38.8^3+3*38.8*a+a^3)*a/(2*38.8^3)*(3*38.8^2-a^2))
end
end
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles=guidata(hObject);
calculate myfunctionmac(RA,a,x)
>> x = 0:deltaa
plot
use Mac
end
if x=(a to38.8)
use Mbc
end
function Mac=myfunctionmac(RA,a,x)
Mac=(RA*2*38.8^3)/(2*38.8^3+3*38.8*a+a^3)*x*(38.8-a)^2/(2*38.8^3)*(3*a+2*(38.8-a))
end
end
handles=guidata(hObject);
calculate Mbc=myfunctionmbc(RA,a,x)
Mbc=(RA*2*38.8^3)/(2*38.8^3+3*38.8*a+a^3)*a/(2*38.8^3)*(2*38.8^3-3*38.8^2*x+a^2*x)
end
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles= giudata(hObject);
calculate function LEac=myfunctionleac(RA,a,x)
for x
if x=(0to a)
use LEac
if x=(a to 38.8)
use LEbc
LEac=(RA*2*38.8^3)/(2*38.8^3+3*38.8*a+a^3)*(38.8-a)^2*x/(12*2.1*10^4*0.2083*38.8^2)*(3*a*38.8^2-x^2*(2*38.8+a))
end
handles= giudata(hObject);
calculate LEbc=myfunctionlebc(RA,a,x)
LEbc=(RA*2*38.8^3)/(2*38.8^3+3*38.8*a+a^3)*(38.8-x)^2*x/(12*2.1*10^4*0.2083*38.8)*(3*(1-a^2/38.8^2)-(3-a^2/38.8^2)*(38.8-x)/38.8)
end
end
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles=guidata(hObject);
calculate myfunctionmd(RA,a,x)
MD=(RA*2*38.8^3)/(2*38.8^3+3*38.8*a+a^3)/(38.8-a)^2*a/(6*2.1*10^4*0.2083*38.8)*(a/(2*38.8+a))^0.5
end
end
function acceptVariableNumInputs(varargin)
disp("Number of input arguments: " + nargin)
celldisp(varargin)
end
This is the code
function Sac=myfunctionac(RA,a)
Sac=(RA*2*38.8^3)/(2*38.8^3+3*38.8*a+a^3)*(38.8-a)^2/(2*38.8^3)*(2*38.8+a)
end
function Mac=myfunctionmac(RA,a,x)
Mac=(RA*2*38.8^3)/(2*38.8^3+3*38.8*a+a^3)*x*(38.8-a)^2/(2*38.8^3)*(3*a+2*(38.8-a))
end
function [MD]= myfunctionmd(RA,a,x)
MD=(RA*2*38.8^3)/(2*38.8^3+3*38.8*a+a^3)/(38.8-a)^2*a/(6*2.1*10^4*0.2083*38.8)*(a/(2*38.8+a))^0.5
end
function [X]=myfunctionxx(a)
X=38.8*( a/(2*38.8+a))^0.5
end
Those are the functions that I want to put in. And by pressing the push button to show a graph.
On this graph.
Ask if you need more information, please.
Isperih - are your myfunction functions (the four that you show above) defined in m-files? Or are they in your GUIDE m-file only?
Looking at one of your callbacks
function pushbutton7_Callback(hObject, eventdata, handles)
handles=guidata(hObject);
calculate myfunctionmd(RA,a,x)
MD=(RA*2*38.8^3)/(2*38.8^3+3*38.8*a+a^3)/(38.8-a)^2*a/(6*2.1*10^4*0.2083*38.8)*(a/(2*38.8+a))^0.5
end
end
you have
calculate myfunctionmd(RA,a,x)
which may or may not be a comment. If it is, then prefix it with %
% calculate myfunctionmd(RA,a,x)
You then have
MD=(RA*2*38.8^3)/(2*38.8^3+3*38.8*a+a^3)/(38.8-a)^2*a/(6*2.1*10^4*0.2083*38.8)*(a/(2*38.8+a))^0.5
end
end
but nowhere have you indicated where the RA or a variables are defined. Does the user enter them into the GUI? Why do you have two end keywords?
Note that if your functions are defined in separate files, then you just call the functions from within the body of your callbacks making sure to pass in the parameters to the function.
All the functions are define in mfiles the varieables will be defined but what is the correct writting of the functions in order the push buttons to work? If you can tell me. How I should write the functions. I am a begginer needs this for University work.
@Isperih Daulov: Sorry, your posted pseudo-code is too confusing for me. Mixing Matlab with some clear text messages like this is not useful:
calculate myfunctionmac(RA,a,x)
>> x = 0:deltaa
plot
use Mac
end
if x=(a to38.8)
use Mbc
end
I cannot guess, what "use Mbc" means. "if x=(a to38.8)" is not clear also.
calculate myfunctionmd(RA,a,x)
MD=(RA*2*38.8^3)/(2*38.8^3+3*38.8*a+a^3)/(38.8-a)^2*a/(6*2.1*10^4*0.2083*38.8)*(a/(2*38.8+a))^0.5
Here I cannot know, what a and x are.
In consequence, trying to convert your message to Matlab would be based on guessing what you might need. But guessing is not the correct way for scientific work on universities.
I think, that only useful way for you is to learn how to program in Matlab. Beside the Getting Started chapters of the documentation there is Matlab's free "Onramp" also to get familiar with the basics (ask an internet search engine for the link).

Answers (0)

This question is closed.

Tags

Asked:

on 29 May 2019

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!