No output in the standalone executable matlab

hello there,
I'm having a weird problem, I have written a code to calculate the volume by integration and made a gui to display the result
when I run the code and input the functions the when I press "calculate volume" as in the attached image the output appear with no problem
but when I use Matlab compiler to make a standalone app the pushbutton never work!!!
please I need an urgent help
note; every other pushbutton are working perfectly except "calculate volume"
here is the code
% --- Executes on button press in calc_vx.
function calc_vx_Callback(hObject, eventdata, handles)
% hObject handle to_x calc_vx (see GCBO)
% eventdata reserved - to_x be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
syms x
func_out =sym(get(handles.input_funcOutx, 'string'));
func_in =sym(get(handles.input_funcInx, 'string'));
axis_rotation = sym(get(handles.input_axisx, 'string'));
func_out1 = pi*(func_out - axis_rotation).^2;
func_in1 = pi*(func_in - axis_rotation).^2;
H=int((func_out1 - func_in1),x,str2double(get(handles.from_x, 'string')), str2double(get(handles.to_x, 'string')));
if (H) < 0
ed = errordlg('Reverse outer and inner functions since volume is negative','Error');
set(ed, 'WindowStyle', 'modal');
uiwait(ed);
else
set(handles.out_cal_vx, 'string', num2str(char(H)));
end
is there a problem with the compiler??

 Accepted Answer

It is never possible to compile anything from the Symbolic Toolbox.

5 Comments

You cannot do what you want to do, without a bunch of trouble.
You want the user to be able to enter two functions as text, and to find the volume between the two.
That works interactively with you using sym up to R2018a; as of R2018a you could do the same thing by calling str2sym() instead of sym() .
You could, with some care, also do the task without using symbolic toolbox when working interactively, as you can use str2func() to convert the user input into a function handle that you could use with integral()/
However, when you compile, there is no possibility of using sym() or str2sym() . When you compile, str2func() can appear, but only in the case where the input is constant, such as
str2func('@(x) x.^3 + 3')
However, str2func() with user input cannot be used when you have compiled.
Therefore in order to do what you want to do, you need to write a small interpreter that can analyze the text of user input, and convert it into calls in terms of routines that you have already written. The difficulty of writing such a parser depends on how much flexibility you want to allow the user. For example, pure polynomials with real integer coefficients are easy. Floating point numbers are a nuisance to get right . Complex numbers are easier than floating point numbers but still have to be taken into account. Then there are potentially the trig functions, the less common trig functions such as cot, the inverse trig functions, natural log, log to an arbitrary base, bessel functions, gamma function, and so on.
thank you for your effort and help, while I don't understand what do you mean by "small interpreter" since I'm new to matlab
I have a question, do you mean that if I use matlab 2018 or above the problem will be solved?7
thank you
No, there is no version of MATLAB in which you can do what you want to do without writing a lot of code.
The process of analyzing character strings to find the components and their proper relationship is known as "parsing" . For example, how should
1+2 * 3
be handled? MATLAB knows about standard operations such as + and * and it knows that * has higher priority than +, so it knows that 1+2 * 3 should be treated as 1 + (2 * 3) . Those of us of sufficient... lived experience.... might remember that there used to be calculators that would take an input of 1 + 2 * 3 as meaning the same as (1 + 2) * 3 .
Now consider for a moment
1 + 2 - 3
and compare that to the nearly identical character vector
1 +2 -3
do they mean the same thing? To some computer languages they do mean the same thing. To MATLAB, they mean very different things.
So parsing is the phase of figuring out how the parts of the character input fit together, which operations are implied by them in which order.
But parsing by itself is not the same as execution: parsing is analysis. Parsing might rewrite into a fully decomposed set of calls, such as converting
x.^5 + sin(pi*x/5)
into
plus( power(x, 5), sin( rdivide( times( pi(), x), 5) ) )
or it might convert into some kind of internal data structure, possibly one that might be represented as
push x
push 5
power()
pi()
push x
times()
push 5
rdivide()
sin()
plus()
This code might all be in a function where x is not known, so it might not be appropriate to execute it to completion at the time of parsing: parsing just has to analyze and leave data suitable for a later phase to efficiently execute.
At some later point you execute with a particular numeric x, in the execution phase.
Between the parsing and the execution phase, there might have been code generation into machine code appropriate for the computer being used. That kind of code generation into machine code is called "compiling". When compiling can be done, the resulting code has the potential to be quite efficient.
But there is no rule that you must generate machine code: it is perfectly valid to have code that analyzes text (parses) and when appropriate it uses the data structures output by parsing in order to execute "on the fly", without compiling. A program that takes in characters representing work to be done and executes the request interactively is known as an "interpreter"
Thank you sir for this helpfull explanation

Sign in to comment.

More Answers (1)

Steven Lord
Steven Lord on 9 Jun 2019
Edited: Steven Lord on 9 Jun 2019
Symbolic Math Toolbox is an ineligible product for MATLAB Compiler. As stated on that page, "this means that an application or component you deploy cannot use functionality from these products." The sym, syms, and int functions are part of Symbolic Math Toolbox and so will not work in a deployed application.
Depending on the specific expression you're trying to integrate, performing the integration before deploying your application and hard-coding the result in your code may be an option. Another potential option is to integrate numerically using the integral function, though if you do that you may need to be careful in creating the anonymous function you're going to pass into the integral function.

1 Comment

thank you. Can you please explain to me how to do the integration befor deploying the app since I'm still a beginner and I don't understand what you mean by that. i.e were do I write this code to make it work wvwn if the volume calculated automatically without pressing the pushbutton that's ok
appreciate your help @stevenlord

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!