I want to display the frequency scale ( 0:1:10 ) on y-axis for the following code:
x=peaks;
f=10; % freq
fval=0:1:f;
mesh(x)
set(gca,'Ydir','reverse')
ylabel('freq. Hz')
xlabel('Samples')
zlabel('Amp.')

 Akzeptierte Antwort

Star Strider
Star Strider am 23 Mai 2016

0 Stimmen

This works:
x=peaks;
f=10; % freq
fval=0:1:f;
mesh(x)
set(gca,'Ydir','reverse')
ylabel('freq. Hz')
xlabel('Samples')
zlabel('Amp.')
yt = get(gca,'YLim'); % Get Y-Limits Values
dyt = 0:10; % Desired Y-Tick Values
set(gca, 'YTick',linspace(min(yt),max(yt),length(dyt)), 'YTickLabel', dyt) % Set New Labels

4 Kommentare

MOHAMMED AL-DALLAL
MOHAMMED AL-DALLAL am 23 Mai 2016
Thanks for replay but when i select any location in figure will show me the old scale as in following photo :
If you want the ‘1:10’ scale to show up on the tooltips, you have to define your y-axis as ‘1:10’, and create it with the meshgrid function.
This should do what you want:
x=peaks;
f=10; % freq
fval=0:1:f;
xv = 0:size(x,2)-1;
yv = linspace(0, 10, size(x,1));
[X,Y] = meshgrid(xv, yv);
mesh(X, Y, x)
set(gca,'Ydir','reverse')
ylabel('freq. Hz')
xlabel('Samples')
zlabel('Amp.')
grid on
MOHAMMED AL-DALLAL
MOHAMMED AL-DALLAL am 23 Mai 2016
Bearbeitet: MOHAMMED AL-DALLAL am 23 Mai 2016
its perfect thank you very much , last asking if i want to change the scale for x-axis ? as example x scale from 0 to 20 ?
is it correct xv = linspace(0, 20, size(x,2));
My pleasure. (Sorry, had to be away for a bit running errands. Life intrudes.)
You ‘xv’ assignment will work as you wrote it, and will do what you want in the meshgrid call:
xv = linspace(0, 20, size(x,2));

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by