Units of kHz in frequency plots
13 views (last 30 days)
Show older comments
When calling functions like pwelch, spectrogram or poctave with no function outputs, MATLAB conveniently provides a plot. That saves me from a lot of code (and potential bugs).
However, the following code (from poctave, I presume something similar occurs elsewhere) makes the plots less intuitive to my eyes, and often cause me to just define the plot from ground up.
% Determine engineering units
[~, scaleFactor, unitsStr] = signal.internal.utilities.getFrequencyEngUnits(CF(end));
...
elseif (value < 1000)
scaleFactor = 1;
unitsStr = 'Hz';
elseif (value < 1000 * 1000)
scaleFactor = 1 / 1000;
unitsStr = 'kHz';
I prefer the x-axis to read:
[3, 8, 20, 50, 126, 316, 794, 1995, 5012, 12589] [Hz]
Rather than:
[0.003, 0.008, 0.020, 0.050, 0.126, 0.316, 0.794, 1.995, 5.012, 12.589] [kHz]
I see that a similar question was asked here, where it is suggested to modify xticks after the fact, which is somewhat more complicated with the use of cathegorical for xticks:
My request would be for a string option ala:
spectrogram(x, N, N/2, N, 48e3, 'Yaxis', 'UseSIBaseUnits')
0 Comments
Answers (1)
Giggs B.
on 3 Aug 2021
I know its late to answer, but for someone who faces the similar problem, try this:
set(gca,'XTick',[0.003, 0.008, 0.020, 0.050, 0.126, 0.316, 0.794, 1.995, 5.012, 12.589])
set(gca,'XTickLabel',[3, 8, 20, 50, 126, 316, 794, 1995, 5012, 12589])
0 Comments
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!