plot the same function with different resolutions on the same plot in matlab

You can plot the same function with different resolutions on the same plot in Matlab by specifying the resolutions for each plot and using the plot function multiple times. Here's an example:

main.m
% Define x values with different resolutions
x1 = linspace(0, 10, 100);     % Higher resolution
x2 = linspace(0, 10, 10);       % Lower resolution

% Define your function (e.g., y = sin(x))
y1 = sin(x1);
y2 = sin(x2);

% Plot the function with different resolutions on the same plot
figure;
plot(x1, y1, 'b', 'LineWidth', 2);  % Higher resolution plot
hold on;
plot(x2, y2, 'r--', 'LineWidth', 1); % Lower resolution plot

% Add labels and title
xlabel('x');
ylabel('y');
title('Plot of sin(x) with Different Resolutions');
legend('High Resolution', 'Low Resolution');

% Show grid
grid on;
591 chars
23 lines

In this example, we defined the x values using linspace with different resolutions, calculated the corresponding y values of the function for each resolution, and then plotted the function using plot multiple times on the same figure. The hold on command ensures that the plots are overlaid on the same plot.

related categories

gistlibby LogSnag