计数和分配变量的提示

时间:2018-09-04 12:06:30

标签: matlab loops count

我的任务是创建一个脚本,用于统计每年VEI >=3的喷发量。然后在屏幕上显示有关VEI >=3的火山名称和日期,并使用VEI >=3保存年度喷发次数。

数据在excel文件中。加载文件后,这是我的脚本写的:

% read the data
[volcname,volcVEI,starteruptyear,starteruptmonth] = textread(inFile,'%s %f %f     %f %*f %*f %*f %*f','headerlines',1,'delimiter',',');

%theVEI is an index for all the VEI >=3
theVEI = find(volcVEI >= 3)
theYear = starteruptyear(theVEI);

Yearvolc = unique(theYear);

startyear = min(Yearvolc);
endyear = max(Yearvolc);

for i = theVEI
    %theVEI(year)
    % Using the index value defined by i, I pluck out 
    screenprint = sprintf('The volcano %s, erupted on year %g, the %g month, with an intensity of VEI     %g',volcname{i},starteruptyear(i),starteruptmonth(i),volcVEI(i));
    disp(screenprint)
end

示例数据:

image

0 个答案:

没有答案