Show only two y values in a plot
显示 更早的评论
Hello all,
Any possible way to show only two value (0.02 and 0.04) for the y-axis, because the other values are just noise.
This is what I use for now to plot:
figure()
plot(time,wavelength,'b-x', 'LineWidth',2)
grid
axis tight
xlabel('Time')
ylabel('Wavelength')
hold on
Thank you!

9 个评论
Dyuman Joshi
2022-12-2
Try
idx=ismember(wavelength,[0.02 0.04]);
%ideally one should use ismembertol
plot(time(idx),wavelength(idx),'b-x', 'LineWidth',2)
Hussein Kokash
2022-12-2
Hussein Kokash
2022-12-2
Dyuman Joshi
2022-12-2
Because the code I wrote only checks for 0.02 and 0.04, which is what you wanted.
Hussein Kokash
2022-12-2
Dyuman Joshi
2022-12-2
This is the problem with floating point numbers, which is why I made the comment.
Try -
idx=ismembertol(wavelength,[0.033333333333333, 0.2],1e-15);
There's still a chance that it might not work, because I don't know the values. If it doesn't, post your data here. Only then can I can say for sure, what you can do.
Hussein Kokash
2022-12-2
Dyuman Joshi
2022-12-2
Alright, did my code work? the one with ismembertol() ?
Hussein Kokash
2022-12-2
回答(1 个)
KSSV
2022-12-2
tol = 10^-3 ; % fix your tolerance
idx = abs(wavelength-0.02)<=tol | abs(wavelength-0.04)<=tol ;
plot(time(idx),wavelength(idx),'+r')
类别
在 帮助中心 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
