Latex Failing for Big Linear System

2 次查看(过去 30 天)
I'm trying to dynamically update an equation in a figure window, but latex seems to be failing for bigger matrices.
n = 20;
m = 1;
A = m*rand(n, n);
B = m*rand(n, 1);
C = A*B;
l = zeros(size(C));
figure; set(gca, 'visible', 'off')
f = gcf; f.Position = [185.8, 423.4, 1089.6, 420];
for i = 1:numel(B)
digits(2)
A_str = latex(sym(A(1:i, :), 'd'));
B_str = latex(sym(B, 'd'));
C_str = latex(sym(C(1:i), 'd'));
myEquation = strcat('$', A_str, B_str, ' = ', C_str, '$');
if i == 1
TT = text(0, 0.5, myEquation, 'Interpreter', 'latex', 'fontsize', 10);
else
TT.String = myEquation;
end
pause(0.5)
l(i) = strlength(myEquation);
end
Warning: Error updating Text.

String scalar or character vector must have valid interpreter syntax:
$\left(\begin{array}{cccccccccccccccccccc} 0.55 & 0.77 & 0.11 & 0.74 & 0.72 & 0.21 & 0.98 & 0.73 & 0.37 & 0.8 & 0.85 & 0.61 & 0.013 & 0.04 & 0.2 & 0.14 & 0.36 & 0.42 & 0.1 & 0.8\\ 0.95 & 0.31 & 0.25 & 0.71 & 0.44 & 0.068 & 0.17 & 0.81 & 0.12 & 0.48 & 0.17 & 0.62 & 0.76 & 0.69 & 0.38 & 0.58 & 0.83 & 0.54 & 0.83 & 0.94\\ 0.26 & 0.2 & 0.81 & 0.25 & 0.26 & 0.37 & 0.39 & 0.14 & 0.18 & 0.93 & 0.23 & 0.18 & 0.17 & 0.36 & 0.91 & 0.27 & 0.56 & 0.86 & 0.5 & 8.9e-3\\ 0.45 & 0.85 & 0.85 & 0.8 & 0.94 & 0.22 & 0.67 & 0.84 & 0.93 & 0.31 & 0.8 & 0.54 & 0.91 & 0.85 & 0.98 & 0.16 & 0.15 & 0.2 & 0.14 & 0.68\\ 0.83 & 0.81 & 0.19 & 0.21 & 0.86 & 0.61 & 0.19 & 0.4 & 0.44 & 0.9 & 0.45 & 0.088 & 0.12 & 0.79 & 0.12 & 0.79 & 0.99 & 0.91 & 0.28 & 0.77\\ 0.95 & 0.81 & 0.39 & 0.12 & 0.4 & 0.78 & 0.51 & 0.79 & 0.5 & 0.17 & 0.56 & 0.41 & 0.38 & 0.36 & 0.091 & 0.27 & 0.75 & 0.23 & 0.96 & 0.7\\ 0.63 & 0.19 & 0.59 & 0.71 & 0.28 & 0.34 & 0.11 & 0.81 & 0.16 & 0.048 & 0.21 & 0.24 & 0.095 & 0.88 & 0.5 & 0.24 & 0.31 & 0.89 & 0.57 & 0.46\\ 0.092 & 0.4 & 0.018 & 0.35 & 0.97 & 0.49 & 0.74 & 0.49 & 0.75 & 0.34 & 0.64 & 0.26 & 0.87 & 0.35 & 0.87 & 0.2 & 0.74 & 0.38 & 0.95 & 0.46\\ 0.59 & 0.28 & 0.79 & 0.82 & 0.34 & 0.58 & 0.99 & 0.69 & 0.48 & 0.68 & 0.88 & 0.074 & 0.88 & 0.83 & 0.31 & 0.88 & 0.31 & 0.55 & 0.43 & 0.23\\ 0.53 & 0.23 & 0.92 & 0.38 & 0.73 & 0.96 & 0.58 & 0.62 & 0.83 & 0.41 & 0.64 & 0.76 & 0.97 & 0.21 & 0.78 & 0.66 & 0.77 & 0.78 & 0.46 & 0.96\\ 0.54 & 0.51 & 0.57 & 0.84 & 0.31 & 0.92 & 0.81 & 0.77 & 0.28 & 0.013 & 0.24 & 0.66 & 0.23 & 0.55 & 0.69 & 0.91 & 0.41 & 0.64 & 0.35 & 0.25\\ 0.26 & 0.094 & 0.97 & 3.0e-3 & 0.64 & 0.21 & 0.019 & 0.88 & 0.7 & 0.63 & 0.35 & 0.35 & 0.65 & 0.88 & 0.78 & 0.36 & 0.14 & 0.71 & 0.47 & 0.99\\ 0.79 & 0.29 & 0.38 & 0.36 & 0.91 & 0.085 & 0.85 & 0.46 & 0.21 & 0.44 & 0.048 & 0.76 & 0.37 & 0.72 & 0.33 & 0.46 & 0.71 & 0.38 & 0.58 & 0.73\\ 0.11 & 0.2 & 0.57 & 0.58 & 0.99 & 0.086 & 0.19 & 0.48 & 0.96 & 0.38 & 0.095 & 0.03 & 0.77 & 0.41 & 0.76 & 0.98 & 0.95 & 0.054 & 0.89 & 0.083\\ 0.6 & 0.09 & 0.87 & 0.89 & 0.25 & 0.6 & 0.083 & 0.36 & 0.44 & 0.42 & 0.92 & 0.94 & 0.54 & 0.53 & 5.0e-3 & 0.45 & 0.76 & 0.16 & 0.74 & 0.64\\ 0.43 & 0.34 & 0.49 & 0.72 & 0.15 & 0.71 & 0.077 & 0.92 & 0.37 & 0.99 & 0.6 & 0.41 & 0.21 & 0.7 & 0.72 & 0.96 & 0.35 & 0.37 & 0.86 & 0.59\\ 0.4 & 0.52 & 0.23 & 0.55 & 0.94 & 0.65 & 0.94 & 0.24 & 0.31 & 0.76 & 0.14 & 0.19 & 0.03 & 0.9 & 0.41 & 0.5 & 0.49 & 0.43 & 0.056 & 0.19\\ 0.99 & 0.75 & 0.075 & 0.58 & 0.37 & 0.59 & 0.019 & 0.76 & 0.14 & 0.68 & 0.86 & 0.94 & 0.84 & 0.44 & 0.093 & 0.36 & 0.45 & 0.46 & 0.49 & 0.13\\ 0.11 & 0.66 & 0.75 & 0.89 & 0.015 & 0.88 & 0.012 & 0.66 & 0.82 & 0.12 & 0.58 & 0.82 & 0.98 & 0.16 & 0.47 & 0.3 & 0.13 & 0.7 & 0.095 & 0.52\\ 0.56 & 0.047 & 0.42 & 0.41 & 0.093 & 0.37 & 0.63 & 0.41 & 0.64 & 0.74 & 0.53 & 0.14 & 0.76 & 0.11 & 0.59 & 0.2 & 0.97 & 0.12 & 0.55 & 0.32 \end{array}\right)\left(\begin{array}{c} 0.24\\ 0.57\\ 0.27\\ 0.46\\ 0.72\\ 0.47\\ 0.81\\ 0.21\\ 0.77\\ 0.43\\ 0.042\\ 0.99\\ 0.19\\ 0.37\\ 0.38\\ 0.67\\ 0.097\\ 0.15\\ 0.35\\ 0.73 \end{array}\right) =\left(\begin{array}{c} 4.7\\ 4.5\\ 3.0\\ 5.7\\ 4.6\\ 4.4\\ 3.2\\ 4.6\\ 4.7\\ 5.9\\ 4.9\\ 4.3\\ 4.9\\ 4.2\\ 4.4\\ 4.6\\ 4.4\\ 4.0\\ 4.3\\ 3.4 \end{array}\right)$
It works fine till n = 8, starts failing for the last iteration at n = 9. Any pointers to make it work for n = 20 would be greatly apprecaited. For n = 20, the number of characters in the equation string exceeds 1200 at i = 7, but the equation stops dislpaying at i = 3.
If copy the eqation string after the last iteration at n = 20 (i.e, n = 20, i = 20), and then insert -> equation -> latex equation and paste it (in a live script), it works as expected.
  3 个评论
Koustubh Gohad
Koustubh Gohad 2023-5-31
Hi Walter,
Can you tell me more? I looked at the using the serial command and setting input buffer size to a higher number, but how do I use the serial object? Is this what you suggested I look at?
Walter Roberson
Walter Roberson 2023-5-31
cla
probes = 1139:1:1140;
for K = 1:length(probes)
msg = "$" + repmat('x', 1, probes(K)-2) + "$";
text(.1, K*0.1, msg, 'interpreter', 'latex');
hold on
drawnow
end
Warning: Error updating Text.

String scalar or character vector must have valid interpreter syntax:
$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$
So 1139 characters works, 1140 characters fails. At least for that set of characters.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2023-5-31
移动:Walter Roberson 2023-6-1
cla
probes = 1:10;
base = repmat('\pi', 1, 300); %900 characters
for K = 1:length(probes)
msg = "$" + base + repmat('x', 1, probes(K)-2) + "$";
text(.1, K*0.1, msg, 'interpreter', 'latex');
hold on
drawnow
end
Warning: Error updating Text.

String scalar or character vector must have valid interpreter syntax:
$\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pi\pixxxxxxxx$
3 character per \pi and repeat that 300 times and add in leading and trailing $ gives us 902+1 and 902+2 working but 902+3 = 905 failing. But when I used repetitions of '. ' or 'x' then failure is at 1139 / 1140. Therefore the buffer size is not strictly by characters: something related to the content being rendered can trigger failure earlier.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Software Development Tools 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by