Draw a box around an equation in MATLAB live editor.

20 views (last 30 days)
David Cole
David Cole about 21 hours ago
Edited: Stephen23 about 5 hours ago
Here is what I want to do.
Is there a direct way to draw a box around an equation directly from equation editor?
Or, do I need to convert the equation to LaTeX? I tried to use the \boxed command in Latex editor but that did not work either.
Without boxed command:
With boxed command (does not work):
Here is my LaTex code for my equation:
$R\left(A^T \right)=\left\lbrace \left\lbrack \begin{array}{c}
1\\
0\\
3\\
0
\end{array}\right\rbrack ,\left\lbrack \begin{array}{c}
0\\
2\\
0\\
-1
\end{array}\right\rbrack \right\rbrace$
I would prefer to just use equation editor without LaTeX.
Thanks

Answers (2)

Umar
Umar 7 minutes ago

Hi @David Cole,

I know you posted a question recently, “I want to avoid fractions in my answer to the null space” and I did post my answer to it as well. It sounds like you are working on a research project. However, I did go through your comments regarding boxing equations directly in the MATLAB equation editor. After reviewing your comments and conducting some research, I wanted to share the solution that might work for you.

You were asking if there is a direct way to box an equation within MATLAB’s equation editor, without having to rely on LaTeX. You also mentioned that you tried using the `\boxed` command in LaTeX, but it didn't work as expected.

The Solution:

Unfortunately, MATLAB's built-in equation editor doesn’t support a direct method to box an equation without using LaTeX. However, the most effective way to achieve the desired result is by using LaTeX within the Live Editor. Specifically, you can use the `\boxed` command around your equation, as follows:

\boxed{
R\left(A^T \right)=\left[\begin{array}{cc}
1 & 0 \\
0 & 2 \\
3 & 0 \\
0 & -1
\end{array}\right]
}

This will render the equation with a box around it when you insert the LaTeX code into MATLAB’s equation editor.

Helpful References:

To make this process easier, here are a few links with more information and step-by-step guides:

1. Inserting LaTeX Equations in MATLAB: [MathWorks Documentation on Equation Editor]( https://www.mathworks.com/help/matlab/matlab_prog/insert-equations.html )

2. Generating LaTeX Code Programmatically in MATLAB: [MATLAB Answers - Generating LaTeX from MATLAB Code]( https://www.mathworks.com/matlabcentral/answers/454936-from-matlab-to-latex )

3. Pretty Equation Viewer (for visual LaTeX formatting): [MATLAB Central - Pretty Equation Viewer]( https://www.mathworks.com/matlabcentral/fileexchange/55477-pretty-equation-viewer )

While the Live Editor's graphical equation editor doesn't support boxing equations directly, LaTeX remains the most effective solution for this. You can use the above LaTeX snippet in the equation editor to box your matrices.

Hope this helps.


Stephen23
Stephen23 about 2 hours ago
Edited: Stephen23 about 2 hours ago
@David Cole: BOXED does not help as MATLAB only supports HBOX and MBOX (which do not draw borders):
As an alternative you could display the equation using the graphics function TEXT (which also allows LaTeX) and use the usual graphics options to create a border:
axh = axes('Visible','off');
text(axh,0.5,0.5,'$R\left(A^T \right)=\left[\begin{array}{cc} 1 & 0 \\ 0 & 2 \\ 3 & 0 \\ 0 & -1 \end{array}\right]$', 'Interpreter','LaTeX', 'EdgeColor','red');
  2 Comments
David Cole
David Cole about 1 hour ago
Moved: Stephen23 about 1 hour ago
Thank you. I have been trying to get boxed working for a while now. But nothing I can do will make boxed work.
Stephen23
Stephen23 about 1 hour ago
Edited: Stephen23 about 1 hour ago
"But nothing I can do will make boxed work."
BOXED is not a supported LaTeX command.
I strongly recommend reading the documentation to know what LaTeX commands are supported:

Sign in to comment.

Categories

Find more on Printing and Saving in Help Center and File Exchange

Products


Release

R2025a

Community Treasure Hunt

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

Start Hunting!