How to set every Data Cursor in each column in this Figure automatically?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Liu Ananiah
el 28 de Oct. de 2020
Editada: Mario Malic
el 4 de Nov. de 2020
a = 1 : 10
b = 1.001 : 10.001
c = 1.002 : 10.002
a = [a;b;c];
a = a (:)';
cg = clustergram(a, 'Cluster', 'row', 'DisplayRange', ceil(max(abs(a))), 'ColumnPDist', 'chebychev', 'Linkage', 'complete', 'Colormap',colormap('jet'), 'DisplayRatio', 1/9)
plot(cg)
Then, I need click every column and set a Data Cursor. It's too boring,
Is there a way to set every Data Cursor in each column in a Figure automatically, not manually?
Thank you in advance!
0 comentarios
Respuesta aceptada
Mario Malic
el 29 de Oct. de 2020
Editada: Mario Malic
el 4 de Nov. de 2020
Edit: Answer updated (was in comments), this code is tested on R2020b and it works. OP wanted code that works with 2018b, for which this doesn't work.
clear
clc;
close all
a = 1 : 10;
b = 1.001 : 10.001;
c = 1.002 : 10.002;
a = [a;b;c];
a = a (:)';
clustergram(a, 'Cluster', 'row', 'DisplayRange', ceil(max(abs(a))), 'ColumnPDist', 'chebychev', 'Linkage', 'complete', 'Colormap','jet', 'DisplayRatio', 1/9);
cgfig = findall(0,'type','figure', 'Tag', 'Clustergram');
cg_im = findall(cgfig, 'type', 'image');
for ii = 2 : 3 : length(a)
datatip(cg_im, 'DataIndex', ii);
end
Edited once again according to Adam's suggestion, now it works properly.
Thanks!
9 comentarios
Adam Danz
el 4 de Nov. de 2020
Editada: Adam Danz
el 4 de Nov. de 2020
+1 Great find applying the datatip to the image object.
Just in case more than 1 image object exists you can get the clustergram figure handle and then the image handle.
cgfig = findall(0,'type','figure', 'Tag', 'Clustergram');
cg_im = findall(cgfig, 'type', 'image');
"I don't know why the additional empty figure keeps getting opened on clustergram"
The colormap is being set by calling the colormap function,
cg = clustergram(. . ., 'Colormap', colormap('jet'), . . .)
When the fig or axis handle is not provided in colormap(__) it uses gcf. However, figure's HandleVisibility in the clustergram is set to 'off' by default. Since gcf() doesn't have access to an existing figure handle, it creates one.
To avoid this, set the colormap as,
cg = clustergram(. . ., 'Colormap', 'jet', . . .)
or
cg = clustergram(. . ., 'Colormap', jet(n), . . .)
Adam Danz
el 4 de Nov. de 2020
Editada: Adam Danz
el 4 de Nov. de 2020
For anyone looking for a solution where datatip is not supported (prior to r2019b), see Method 5 in this answer.
Más respuestas (0)
Ver también
Categorías
Más información sobre Expression Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!