Can I reshape a function handle? Or change the numeric format of a function handle?
Show older comments
Greetings.
I have created a function to solve the time-invariant state equations. The function returns three outputs which are function handles (the argument is t): x, y, and phi. When I execute the function, take only x for an example, I get n functions (n is the order of my system), so if n is 3, I get something like:
x = @(t)[exp(t.*(-6.431041321077914e-1));exp(t.*(12.4342817231314e-1));exp(t.*(-6.431041321077914e-1)).*4.35559619931756e-1-exp(t.*(-3.07978528369903e-1))]
These are three functions. The questions here are:
1. Can I change the format of the output function to be something easier to read? The numbers to the right of the decimal point are way too much and useless to me, 3 points will do. I have tried
format short
but it does not work on functions.
2. If I can't change the format, can I reshape this function to be an array of 3 functions? i.e. every function is in one row like this
x = exp(t.*(-6.431041321077914e-1))
exp(t.*(12.4342817231314e-1))
exp(t.*(-6.431041321077914e-1)).*4.35559619931756e-1-exp(t.*(-3.07978528369903e-1))
The main point here is that I am trying to plot each of these functions aside using fplot (my version is R2015b so fplot does not work with symbolic expressions), so if there is another way I am not thinking of to plot the data, it solves my problem too.
Thank you very much in advance,
M. Ayoub.
Accepted Answer
More Answers (1)
Steven Lord
on 6 Feb 2018
0 votes
My guess is that you created your function handle using the matlabFunction function or a similar function from Symbolic Math Toolbox. Looking at the documentation it doesn't appear to have any way to control to how many decimal places the numeric values of symbolic expressions that represent numbers are written. You may want to try calling the digits function before calling matlabFunction to see if that impacts how the numbers are written in the function handle's code.
If instead you called sprintf or num2str to generate a text vector that you then converted to a function handle using str2func, change the format specifier in your sprintf or num2str calls or specify a precision in num2str.
1 Comment
Mohammad Ayoub
on 6 Feb 2018
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!