Clear Filters
Clear Filters

in y axis i want 10^(-2000). can anyone plz help

4 views (last 30 days)
set(gca, 'YScale', 'log')
ylim ([0 1e-308])
Instead of 1e-308 i want 1e-2000. how can i set the limit plz

Accepted Answer

Hassaan
Hassaan on 21 May 2024
Assummed use case may help:
clc; clear all; close all;
% Generate dummy frequency data
f = linspace(0, 1000, 1000); % Frequency vector from 0 to 1000 Hz
% Generate dummy PSD data with very small values
PSD = 10.^(-2000 + randn(1, 1000) * 10); % Generate PSD data around 10^(-2000)
% Rescale the PSD to avoid numerical underflow
scale_factor = 10^2000;
rescaled_PSD = PSD * scale_factor;
% Plot the rescaled PSD
figure;
plot(f, rescaled_PSD);
title('Power Spectrum Density');
xlabel('Frequency (Hz)');
ylabel('Power/Frequency');
grid on;
% Set the y-axis to logarithmic scale
set(gca, 'YScale', 'log');
% Adjust y-axis tick labels to reflect the original scale
yticks = get(gca, 'YTick'); % Get current y-axis tick values
yticklabels = arrayfun(@(x) sprintf('10^{%d}', log10(x) - 2000), yticks, 'UniformOutput', false);
set(gca, 'YTickLabel', yticklabels);
% Set appropriate y-axis limits
ylim([10^-2000, 10^2]); % Adjust according to the range of your data
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

More Answers (1)

Walter Roberson
Walter Roberson on 21 May 2024
1e-2000 would underflow to 0. You can only use such a number symbolically... but symbolic numbers cannot be used as limits.
You also cannot plot() such small numbers. I am not sure it is possible to fplot() them either.
Your best bet would be to rescale your numbers to something like 0 to 100 and then change your ytick labels to lie about the range.
  3 Comments
Kasmita Devi
Kasmita Devi on 21 May 2024
Actually, I am getting my error 10^(-2000) which is very less and that is superior result as compared to existing results. so i want to plot that in y axis.
Steven Lord
Steven Lord on 21 May 2024
You can show the text "1e-2000" on the axes.
plot(1, 1, 'o')
xticks(1)
xticklabels('1e-2000')
But as Walter stated, you cannot represent 1e-2000 as a double precision number. It underflows to 0. If you can't represent it as a double precision number, you can't plot it.
x = 1e-2000 % underflow
x = 0
x == 0 % x is exactly, down to the last bit, zero
ans = logical
1
figure
h = plot(x, 1, '+');
h.XData % exactly zero
ans = 0

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!