How to extract colorbar value of all pixels in figure?

17 ビュー (過去 30 日間)
Noah
Noah 2017 年 5 月 24 日
For example, if the following documentation code is used...
figure(1)
N = 1024;
n = 0:N-1;
w0 = 2*pi/5;
x = sin(w0*n)+10*sin(2*w0*n);
s = spectrogram(x);
spectrogram(x,'yaxis')
The spectogram attached is produced, and when the data cursor is used, the value "index" gives the pixels value on the colorbar. How can I extract this value for all pixels in the figure?

回答 (1 件)

J Philps
J Philps 2017 年 5 月 30 日
The color data can be accessed through the CData of the Image. I have modified your sample code to populate the variable 'spectData' with the corresponding 'Index' information that you were accessing through the data cursor:
figure(1); N = 1024; n = 0:N-1; w0 = 2*pi/5; x = sin(w0*n)+10*sin(2*w0*n); s = spectrogram(x); spectrogram(x,'yaxis')
ax = gca; spectData = ax.Children.CData;
The resulting spectData will be a 129x7 double.
  1 件のコメント
Prasanth Thangavel
Prasanth Thangavel 2019 年 9 月 5 日
Great answer. It worked like a charm!

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by