winuall
winuall

Reputation: 369

Set ticks according to formula

Given a figure created by spectrogram function, how do I set the ticks according to the following formula?

(12 × log2 (f / 440)) + 69

[f is the current value on the axis, and the formula's result should replace it]

Upvotes: 1

Views: 381

Answers (1)

FakeDIY
FakeDIY

Reputation: 1445

If I understand your question right...There might be a more efficient way, but I think this works:

data = rand(1,1000);

plot(data)
f = get(gca,'Xtick');
new_ticks = (12 * log2((f / 440) + 69))
set(gca,'Xticklabels', new_ticks)

This keeps the x-axis scaling the same, but changes the tick labels according to the formula you gave.

Upvotes: 4

Related Questions