Azzera filtri
Azzera filtri

Custom Display for symbolic Object

2 visualizzazioni (ultimi 30 giorni)
Justin Ferland
Justin Ferland il 20 Apr 2024
Commentato: Walter Roberson il 20 Apr 2024
Hello,
I do alot of work with symbolic variables and latex, and I would like to have some custom output for when a semi colon is not put at the end of a line, I would like it to output the formated version of the symbolic variable so that I can use the copy as LaTeX. An example of how I would like it displayed is below, when I run the line sigma_i = 10*u.MPa I would like it to be displayed as if I had run myFunc.
u =symunit;
sigma_i =10*u.MPa
sigma_i = 
myFunc(sigma_i)
function myFunc(inputValue)
varName = inputname(1);
symbolicVarName = sym(varName);
disp(vpa(symbolicVarName == inputValue, 3)); % Adjust the precision as needed
end
I have tried creating class MySym which inherits from sym but whenever I do any operations the output ends up being a sym
classdef MySym < sym
methods
% Constructor method
function obj = MySym(val)
% Convert input to sym and store it in the object
obj = obj@sym(val); % Call superclass constructor
end
% Custom display method
function display(obj)
varName = inputname(1);
if isempty(varName)
varName = 'ans';
end
symbolicVarName = sym(varName);
disp(vpa(symbolicVarName == obj, 3)); % Display with 3 digits precision
end
end
end

Risposte (0)

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by