MATLAB Lab Assignment - Plotting
MATLAB - Plotting
MATLAB Code:
x = 1:10;
y = x.^2;
plot(x,y)
title('Basic Plot')
xlabel('X-axis')
ylabel('Y-axis')
grid on
Output shown above.
MATLAB - Plot Arrays
MATLAB Code:
A = [1 2 3 4 5];
B = [2 4 6 8 10];
plot(A,B)
title('Plot Arrays')
Output shown above.
MATLAB - Plot Vectors
MATLAB Code:
x = [1 2 3 4 5];
y = [5 4 3 2 1];
plot(x,y,'r-*')
title('Vector Plot')
Output shown above.
MATLAB - Bar Graph
MATLAB Code:
x = [1 2 3 4 5];
y = [5 7 3 8 4];
bar(x,y)
title('Bar Graph')
Output shown above.
MATLAB - Histograms
MATLAB Code:
data = randn(1000,1);
histogram(data)
title('Histogram')
Output shown above.
MATLAB - Graphics
MATLAB Code:
rectangle('Position',[1 1 4 2])
axis([0 10 0 10])
title('Graphics Example')
Output shown above.
MATLAB 2D Line Plot
MATLAB Code:
x = 0:0.1:10;
y = sin(x);
plot(x,y)
title('2D Line Plot')
Output shown above.
MATLAB - 3D Plots
MATLAB Code:
[X,Y] = meshgrid(-5:0.5:5);
Z = sin(sqrt(X.^2 + Y.^2));
surf(X,Y,Z)
title('3D Plot')
Output shown above.
MATLAB - Formatting a Plot
MATLAB Code:
x = 0:0.1:10;
y = cos(x);
plot(x,y,'g--','LineWidth',2)
title('Formatted Plot')
xlabel('Time')
ylabel('Value')
grid on
Output shown above.