clear
clc
%==================================================================================
%最大似然法求b值-------41.8-45.8N ,85.7-89.7E
%==================================================================================
%==================================================================================
%数据格式-------longitude latitude year month day magnitude focal hour minute
%==================================================================================
load('EQ.mat');% 若读取excel文件A=xlsread(~);
%load('EQ.mat')后workplace的矩阵名为A,不为A的要重命名为A并save as覆盖掉原EQ.mat文件
degree=input('扫描窗口(度)大小:');
for d=1:1:ceil(4/degree)
for e=1:1:ceil(4/degree)%取整函数ceil(x)取大于x的最小整数
for c=1:1:length(A)
x=A(c,1);
y=A(c,2);
if x>=85.7+(d-1)*degree && x<=85.7+d*degree && y>=41.8+(e-1)*degree && y<=41.8+e*degree
u=A(c,6);
C=[[],u]; %把结果x存到数组C中
end
end
magnitude=unique(C);
n=hist(C,magnitude);
n1=fliplr(n);
N1=cumsum(n1);
N=fliplr(N1);
if N<10
b=0;
else
[p,s]=polyfit(magnitude,log10(N),1);
b=abs(p(1,1));
end
end
end
不行,运行出错,undefined function or variable ‘C’
追答在最开始定义C=[];
追问我试了一下,在最开始定义C=[]好像解决了,多谢了。