MATLAB: Legend something wrong

legendloglogplotting

I got some sample codes from this
I am not sure why plotting some with wrong legends : (
clear;clc;close all;
h = [0.05 0.025 0.0125 0.00625 0.003125];
A = [0.0103 0.005 0.0019 0.0121 0.1031];
B = [0.0103 0.0052 0.0026 0.0012 0.0011];
C = [0.0103 0.0052 0.0026 0.0013 0.0011];
% Plot filtered data
figure();
%axis([0 3.5e-3 0 1e-3]);
loglog(h, A,'k-'); % plot
hold on;
scatter(h,A,'k','*');
loglog(h, B,'k--');
scatter(h,B,'k','d');
loglog(h, C,'k:');
scatter(h,C,'k','o');
xlabel('grid space [m]')
ylabel('Error Value');
title('Relation of Error Value and Grid Spacing [m]')
legend('A','B','C');
hold off;
grid on;

Best Answer

No need to call loglog and scatter seperately. loglog() can do both
% clear;clc;close all;
h = [0.05 0.025 0.0125 0.00625 0.003125];
A = [0.0103 0.005 0.0019 0.0121 0.1031];
B = [0.0103 0.0052 0.0026 0.0012 0.0011];
C = [0.0103 0.0052 0.0026 0.0013 0.0011];
% Plot filtered data
figure();
%axis([0 3.5e-3 0 1e-3]);
loglog(h, A,'k-*'); % plot
hold on;
loglog(h, B,'k--d');
loglog(h, C,'k:o');
xlabel('grid space [m]')
ylabel('Error Value');
title('Relation of Error Value and Grid Spacing [m]')
legend('A','B','C');
hold off;
grid on;
Related Question