Question: MATLAB Index exceeds matrix dimensions. Error in spots2 (line 11) spots= [spots, str2double(parts(2))]; clear all; clc; close all; fid = fopen('sunspots.txt'); tline = fgets(fid); monthnumber

MATLAB

Index exceeds matrix dimensions.

Error in spots2 (line 11) spots= [spots, str2double(parts(2))];

clear all;

clc;

close all;

fid = fopen('sunspots.txt');

tline = fgets(fid);

monthnumber = [];

spots = [];

while ischar(tline)

parts = strsplit(tline,'\t');

monthnumber = [monthnumber; str2double(parts(1))];

spots= [spots; str2double(parts(2))];

tline = fgets(fid);

end

fclose(fid);

r = 100;

start = 1;

vv = [];

entries = [];

i = 1;

while(start+ 2*r < size(spots,1))

ss = sum(spots(start:start + 2*r,1)/(2*r));

vv =[vv;ss];

entries = [entries;i];

i = i+1;

start = start + 2*r + 1;

end

plot(entries,vv)

xlabel('Month Number');

ylabel('Spots on Sun');

axis([1 size(vv,1) 1 100]);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!