![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1136220/image.png)
How can I use html in UItable for draw line??
5 views (last 30 days)
Show older comments
Hi all,
I want to instead line legend by table.
Following is example.
app.Panel_3.AutoResizeChildren = 'off';
app.ax4 = subplot(1,1,1,'Parent',app.Panel_3);
t=-10:1:10;
t_sin = sin(t);
plot(app.ax4,t,t_sin, '-ro', 'DisplayName','sin(t)');
hold(app.ax4,"on");
plot(app.ax4,t,tan(t), '-bo', 'DisplayName','tan(t)');
app.UITable.ColumnName = {'Line', 'Name', 'Check'};
%% Get all line of app.ax3
ax4_allLines = findobj(app.ax4, 'type', 'line');
ax4_allLinesName = {};
for id = 1:length(ax4_allLines)
linecolor = rgb2hex(ax4_allLines(id).Color);
marker = ax4_allLines(id).Marker;
if strcmp(marker,'none')
marker=[];
end
linestyle = ax4_allLines(id).LineStyle;
ax4_allLinesName{end+1, 1} = ['<hr style="height:2px;border-width:0;color: ' linecolor '">'];
ax4_allLinesName{end, 2} = ax4_allLines(id).DisplayName;
ax4_allLinesName{end, 3} = true;
end
app.UITable.Data = ax4_allLinesName;
% s = uistyle("Interpreter","html");
% addStyle(app.UITable,s);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1136200/image.png)
you can see that, when I tried to use HTML to draw line, it couldn't.
My expect.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1136205/image.png)
Or has marker is excilent.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1136210/image.png)
Do anyone have idea? Could you give me.
Thank you so much
0 Comments
Accepted Answer
Eric Delgado
on 26 Sep 2022
uitable doesn't have a html interpreter. So... below is my approach to this issue.
app.UITable.Data = table(["–––––o–––––"; "–––––o–––––"], ["tan(t)"; "sin(t)"], [true; true]);
s1 = uistyle('FontColor','b', 'HorizontalAlignment', 'center', 'FontWeight', 'bold');
s2 = uistyle('FontColor','r', 'HorizontalAlignment', 'center', 'FontWeight', 'bold');
addStyle(app.UITable, s1, "cell", [1,1])
addStyle(app.UITable, s2, "cell", [2,1])
You will get...
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1136220/image.png)
4 Comments
Eric Delgado
on 26 Sep 2022
I think a slider could be a solution. Not as beautiful as controlling directly the panel, but...
% Value changing function: Slider
function SliderValueChanging(app, event)
x1 = (event.Value+1)/2;
x2 = 1-x1;
app.GridLayout.ColumnWidth(1:2) = {sprintf('%fx', x1), sprintf('%fx', x2)};
end
You could get something like this... (see attached app made in R2021b)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1136555/image.png)
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!