醉資心最近掛了,害我無法查我以前紀錄下來的 matlab 常用功能,只好也在blog備份一篇。
How can I select multiple points using the Data Cursor and export the coordinates to the MATLAB workspace?
來源: mathworks , datacursormode
steps -
- plot the figure
- click the Data Cursor button on the toolbar
- click any point of your choice on the figure. if you wanna set multiple points, press Alt key.
- right-click anywhere on the figure –> “export cursor data to workspace” –> enter variable name –> enter
他會將cursor data存成structure,每個element有三個欄位。
- Target : 這筆cursor來自哪個figure (handle)
- Position: 座標
- DataIndex: 這筆cursor位於每個陣列的哪個位置
程式自動化的作法:
fig = figure;
z = peaks;
plot(z(:,30:35))
dcm_obj = datacursormode(fig);
set(dcm_obj,'DisplayStyle','datatip',...
'SnapToDataVertex','off','Enable','on')
% Now, click on the line to place datatip before executing the next line of code.
c_info = getCursorInfo(dcm_obj)
How to plot an image onto another one transparently ?
在Audio Signal Processing的實驗中,我們會很常需要把實驗結果貼在spectrogram上來看,用imagesc function來畫spectrogram會比用spectrogram function快很多,因為前者是2D後者是3D。在我用imagesc畫完後想要新增一張新的image貼在上面時試了很多方法,例如:
h1 = image(plot_t, plot_f, ones(size(MskMaxtrix)), 'AlphaData', 0.2*(1-MskMaxtrix), 'CData', colormap(flipud(copper(2))));
或
h1 = image(plot_t, plot_f, ones(size(MskMaxtrix)),'CData',colormap(flipud(copper(2))));
或者乾脆先畫出值再調整colormap
h1 = image(plot_t, plot_f, 0.1*ones(size(MskMaxtrix)));
colormap(flipud(copper(2)));
通通沒用!最後解決的方法如下:
green = cat(3, zeros(len_f, len_t), ones(len_f, len_t), zeros(len_f, len_t)); |
先畫完後,再用set去調整 alphadata 屬性。這裡的MskMaxtrix是一個非0即1的矩陣,1代表通過,0代表沒通過,因此上面的例子是為了畫沒通過(過濾掉)的頻譜,0.2代表透明程度。
沒有留言:
張貼留言