- Plot the Data: First, plot your data using loglog.
- Calculate the Slope: For the equation ( y = \exp(0.3) \cdot x^1 ), the slope is 1 on a log-log plot.
- Add Custom Lines: Use the line function to add lines with the desired slope.
how to change slope of the grid line in logarithmic scale?
2 次查看(过去 30 天)
显示 更早的评论
x=1:10; y=exp(.3).*x.^(1); % equation 1 loglog(x,y); grid on
I want to change the grid line of y axis with slope of equation 1.
0 个评论
回答(1 个)
BhaTTa
2024-8-26
To change the grid lines of the y-axis to match the slope of your equation on a log-log plot, you can use MATLAB's loglog function along with custom grid line settings.
Here's how you can do it:
Here's a sample script to achieve this:
% Define the data
x = 1:10;
y = exp(0.3) .* x.^(1);
% Plot the data
figure;
loglog(x, y, 'b-', 'LineWidth', 2);
hold on;
grid on;
% Define the slope (m = 1 for equation y = exp(0.3) * x^1)
slope = 1;
% Define starting point for the custom grid line
x_start = min(x);
y_start = min(y);
% Define a range for the custom grid line
x_line = [x_start, max(x)];
y_line = y_start * (x_line / x_start).^slope;
% Plot the custom grid line
line(x_line, y_line, 'Color', 'r', 'LineStyle', '--', 'LineWidth', 1.5);
% Add labels and title
xlabel('x');
ylabel('y');
title('Log-Log Plot with Custom Slope Grid Line');
legend('Data', 'Custom Slope Line');
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!