フィルターのクリア

Custom Display for symbolic Object

2 ビュー (過去 30 日間)
Justin Ferland
Justin Ferland 2024 年 4 月 20 日
コメント済み: Walter Roberson 2024 年 4 月 20 日
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
  1 件のコメント
Walter Roberson
Walter Roberson 2024 年 4 月 20 日
disp(latex(vpa(symbolicVarName == obj, 3)));
perhaps ?

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Variables, Expressions, Functions, and Preferences についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by