How to plot a line on top of the continuous wavelet transform (CWT) output?
9 次查看(过去 30 天)
显示 更早的评论
Hello. According to the attached figure, I want to add a horizontal green line (at a scale of 60) on top of the continuous wavelet transform (CWT) output. However, the line is positioned below the CWT output. Your assistance with this request would be greatly appreciated.
0 个评论
采纳的回答
dpb
2024-7-17
编辑:dpb
2024-7-17
data = xlsread('signal.xlsx','1');
% Extract the time and signal columns
t = data(:, 1);
signal = data(:, 2);
dt = t(3) - t(2); % sampling time
fs = 1/dt; % freq
wname = 'bior6.8';
N = length(signal);
tv = (0:N-1)/fs;
% Compute the CWT coefficients
scales = 1:200;
C = cwt(signal,scales,wname);
% Create a meshgrid fot the time and scales
[T,S] = meshgrid(tv,scales);
% Plot the CWT coefficients with time and scales
figure;
hS=surf(T,S,abs(C),'EdgeColor','none');
% leave in 3D view for now for demo purposes
%view(0,90); % Set the view to 2D
xlabel('Time (sec)');
ylabel('Scale');
xlim([0, T(end)]);
grid off
colormap (pink(240));
set(gca,'fontname','Times New Roman','FontSize',10)
hold on
SCA = 60;
% left following in temporarily for demo purposes...
plot(xlim,[1 1]*(SCA),'-r','LineWidth',2)
Illustrates the problem/issue; a 2D line parallel to the x axis with its z height equal to 0 is obscured by the surface and the color map chosen is dark enough to prevent the line from showing through. Making the surface less opaque lets one see where the line is located, but it took going to such a low value for .FaceAlpha that the surface itself is then difficult to see for the lighter shades.
So, how to fix? The problem is one needs to draw the line at or above the surface in the 3D axes space even though the desired presentation is from the Z axis direction directly towards the x,y plane. Hence, yline or its workalikes aren't the correct tool for the job, we need plot3 instead.
Z=max(abs(C),[],'all'); % max Z so can be at or above any point in surface
hL3=plot3(xlim,[SCA SCA],[Z Z],'g-','linewidth',2);
pause(10) % for demonstration -- remove when going to final use
view(0,90); % Set the view to 2D after seeing original for a while
I left in the initial line on the Z==0 plane and commented on it and later...to illustrate, the above code as is will show the surface and then the red line in 3D view and add the green line at Z==max(C), then pause for 10 seeconds so can see the result before then switch the viewpoint to the 2D plane view at which time the green line will appear on top and obscure the red line. Remove those extra pieces to use "in anger", obviously.
Sorry it took me so long to think of the cause of the problem after which the solution is obvious...
更多回答(1 个)
dpb
2024-7-12
编辑:dpb
2024-7-12
From one of the examples it appears that other than (rudely) executing a clf that clears any current figure when called, it looks like cwt simply creates an ordinary axis that can be accessed in the normal HG2 ways...
load kobe
cwt(kobe,1)
hAx=gca;
hold on
yline(60,'g','linewidth',2)
Attach a minimum working example that produces your example plot above if want/need something more specific,
9 个评论
dpb
2024-7-15
Lacking real data, we'll use one of the surf examples to 'spearmint with...
[X,Y,Z] = peaks(25);
CO(:,:,1) = zeros(25); % red
CO(:,:,2) = ones(25).*linspace(0.5,0.6,25); % green
CO(:,:,3) = ones(25).*linspace(0,1,25); % blue
hS=surf(X,Y,Z,CO,'edgecolor','none');
view(0,90)
xlabel('X'),ylabel('Y')
yline(0,'r')
I thought maybe the peaks would hide the line but they didn't seem to...we simply must have the actual code.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Continuous Wavelet Transforms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!