Question

Please use Mat lab only. Thanks (b) Plotting Sunspots Load the Matlab data file, sunspot.dat, and...

Please use Mat lab only. Thanks

(b) Plotting Sunspots

Load the Matlab data file, sunspot.dat, and experiment with making plots and subplots. The file is a simple 288 row by 2 column matrix where the first column has consecutive years from 1700 until 1987 and the second column has the mean sunspot number for that year. Then we will construct year and spots vectors from the two columns and plot spots as a function of year.

load sunspot.dat;

year = sunspot(:,1); %puts year data in a vector

spots = sunspot(:,2); %puts spot data in a vector plot(year,spots);

plot (year,spots);

This gives a 2-D plot displayed as a solid blue line going through the points.To add point markers, add a third string argument, e.g., 'r*' for data points being displayed as red asterisks. There is a toggle for getting a new plot (hold off) and for superimposing on an existing plot (hold on). hold on;

plot(year,spots, 'r*')

xlabel("Year")

ylabel("Number of Spots")

title("Sunspots vs. Time")

For the exercise, create a subplot grid of (3,1) (3 plots arranged vertically). The plots should be a stem plot, an area plot, and a line plot. Each plot should be labeled on the x and y axes.

Please use Mat lab only. Thanks

Homework Answers

Answer #1

% Program as per question for plot and subplot

clc

clear all

close all

load sunspot.dat;
year = sunspot(:,1); %puts year data in a vector
spots = sunspot(:,2); %puts spot data in a vector plot(year,spots);
hold on

plot(year,spots, '-r*')
xlabel('Year')
ylabel('Number of Spots')
title('Sunspots vs. Time')

figure,
subplot(311)
stem(year,spots)
xlabel('Year')
ylabel('Number of Spots')
title('Sunspots vs. Time')
grid on

subplot(312)
bar(year,spots)
xlabel('Year')
ylabel('Number of Spots')
axis([1700,2000,0,200])
title('Sunspots vs. Time')
grid on

subplot(313)
plot(year,spots)
xlabel('Year')
ylabel('Number of Spots')
title('Sunspots vs. Time')
grid on

% End of the program

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions