Select lines on a surf plot and output indices

2 ビュー (過去 30 日間)
Butterflyfish
Butterflyfish 2021 年 11 月 16 日
コメント済み: Butterflyfish 2021 年 11 月 16 日
I have a plot (spectrogram) on which I added some lines. I would like to select some of these lines directly on the plot with the mouse and output the index of each selected line.
Here is part of my script for the plot
figure
hold on
H(1) = surf(t,f,20*log10(abs(s)),'EdgeColor', 'none');
axis xy; axis tight;
colormap(jet); view(0,90);
xlabel('Time (secs)');
colorbar;
ylabel('Frequency(Hz)');
% Add lines
ipt_sec = t(ipt); % Indices to seconds
for i = 1:numel(ipt_sec)
y = ylim;
H(i)= plot([ipt_sec(i),ipt_sec(i)],[y(1) y(2)], 'LineWidth', 2, 'Color', 'k');
end
set(H, 'ButtonDownFcn', {@LineSelected, H})
function LineSelected(ObjectH, EventData, H)
set(ObjectH, 'LineWidth', 4);
set(H(H ~= ObjectH), 'LineWidth', 2);
end
I would like to be able to select multiple lines (instead of just one in the script above) and output each of their index.
Any help greatly appreciated, thank you!

回答 (1 件)

KSSV
KSSV 2021 年 11 月 16 日
編集済み: KSSV 2021 年 11 月 16 日
Just use
surf(20*log10(abs(s)),'EdgeColor', 'k')
Use getpts or ginput or daatip, this will give you location/ index where you have clicked on the plot. It has (i,j) r (row,column). Now you can use t(r,:) or t(:c) etc.
But why you want to click on the plot? You can use ==, <=, >= etc to get what you want.
  3 件のコメント
KSSV
KSSV 2021 年 11 月 16 日
編集済み: KSSV 2021 年 11 月 16 日
Select two points which lie on the same line.....you have the indices now.
Note that the colors are decided by the magnitude or value of the data. Still you can use logical comparisons.
Butterflyfish
Butterflyfish 2021 年 11 月 16 日
Thanks, I have edited my question for more precisions. The function 'ButtonDownFcn' seems to work but I don't understand completely how it works, how to select multiple lines and output the indices.

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

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by