How to set every Data Cursor in each column in this Figure automatically?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
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!

Accepted Answer
Mario Malic
on 29 Oct 2020
Edited: Mario Malic
on 4 Nov 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 Comments
Liu Ananiah
on 29 Oct 2020
I want to get color matrix and index by Data Cursor. Could you have any great ideas?
Mario Malic
on 29 Oct 2020
Edited: Mario Malic
on 29 Oct 2020
I found it, I don't know why the additional empty figure keeps getting opened on clustergram.
clear
clc;
close all
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);
cg_im = findall(0, 'type', 'image'); % Take a look at children/parent properties to see where the things are, as it looks a bit messy to me
for ii = 2 : 3 : length(a)
datatip(cg_im, 'DataIndex', ii);
end
Liu Ananiah
on 30 Oct 2020
‘I don't know why the additional empty figure keeps getting opened on clustergram.’
So am I.
By using datatip() can achieve it, but it's only supported in r2019b and later. Unfortunately, my version is r2018a.
I will continue to seek the way to solute this problem. I would appreciate it if you could give me a hand. Thank you for your help!
Ananiah
Mario Malic
on 30 Oct 2020
Check here, this might be helpful https://www.mathworks.com/matlabcentral/fileexchange/19877-makedatatip
Liu Ananiah
on 31 Oct 2020
I saw it. It does not work as I wish, maybe the Figure from clustergram is different.
Mario Malic
on 31 Oct 2020
Edited: Mario Malic
on 3 Nov 2020
Yes, datatips are different whether you use figure from clustergram or plot. Try it on plot figure.
Edit:
My mistake, try it on clustergram figure.
Liu Ananiah
on 3 Nov 2020
In a way, I need to use clustergram first ;(
+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), . . .)
For anyone looking for a solution where datatip is not supported (prior to r2019b), see Method 5 in this answer.
More Answers (0)
Categories
Find more on Expression Analysis in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)