Latex Failing for Big Linear System
1 view (last 30 days)
Show older comments
Koustubh Gohad
on 31 May 2023
Edited: Koustubh Gohad
on 1 Jun 2023
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
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 Comments
Walter Roberson
on 31 May 2023
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
So 1139 characters works, 1140 characters fails. At least for that set of characters.
Accepted Answer
Walter Roberson
on 31 May 2023
Moved: Walter Roberson
on 1 Jun 2023
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
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.
More Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!