为什么光谱数据求导只求出了前1010个数据点(共计3471个数据点),后面的2461个数据点都是错误的数据
定义一个光谱数据类如下:class IRSData
{
public:
IRSData();
virtual ~IRSData();
public:
void DrawSpectralLine();
void Firstderivate();
void Secondderivate();
void Drawspectrum(int excelrows);
void Drawspectrum(int begin,int end);
void Drawfirstderivate(int excelrows);
void Drawsecondderivate(int excelrows);
int rows;
double m_IRSData[4000][2];
double m_Firstderivate[3999][2];
double m_Secondderivate[3998][2];
CPoint m_EPoint;
CPoint m_SPoint;
};
IRSData::IRSData()
{
for(int i=0;i<4000;i++)
{
m_IRSData[i][0]=(float)i+1;
m_IRSData[i][1]=(float)50;
}
for(int i=0;i<3999;i++)
{
m_Firstderivate[i][0]=(float)i+1;
m_Firstderivate[i][1]=(float)100;
}
for(int i=0;i<3998;i++)
{
m_Secondderivate[i][0]=(float)i+1;
m_Secondderivate[i][1]=(float)100;
}
}
IRSData::~IRSData()
{
}
void IRSData::DrawSpectralLine()
{
}
void IRSData::Firstderivate()
{
for(int i=0;i<3999;i++)
{
m_Firstderivate[i][0]=(m_IRSData[i+1][0]+m_IRSData[i][0])/2;
m_Firstderivate[i][1]=(m_IRSData[i+1][1]-m_IRSData[i][1])/(m_IRSData[i+1][0]-m_IRSData[i][0]);
}
}
void IRSData::Secondderivate()
{
for(int i=0;i<3998;i++)
{
m_Secondderivate[i][0]=(m_Firstderivate[i+1][0]+m_Firstderivate[i][0])/2;
m_Secondderivate[i][1]=(m_Firstderivate[i+1][1]-m_Firstderivate[i][1])/(m_Firstderivate[i+1][0]-m_Firstderivate[i][0]);
}
}
void IRSData::Drawspectrum(int excelrows)
{
for(int er=0;er<excelrows-1;er++)
{
m_SPoint.x=(long)m_IRSData[er][0];
m_SPoint.y=600-(long)m_IRSData[er][1];
m_EPoint.x=(long)m_IRSData[er+1][0];
m_EPoint.y=600-(long)m_IRSData[er+1][1];
if(!m_EPoint.x==0)
{
CClientDC dc(AfxGetApp()->GetMainWnd());//使用cclientDC类的好处是该资源可以自动释放,而不用人工的释放
dc.MoveTo(m_SPoint);
dc.LineTo(m_EPoint);
}
}
}
void IRSData::Drawspectrum(int begin,int end)
{
for(int er=begin;er<end-1;er++)
{
m_SPoint.x=(long)m_Firstderivate[er][0];
m_SPoint.y=600-(long)m_Firstderivate[er][1];
m_EPoint.x=(long)m_Firstderivate[er+1][0];
m_EPoint.y=600-(long)m_Firstderivate[er+1][1];
if(!m_EPoint.x==0)
{
CClientDC dc(AfxGetApp()->GetMainWnd());//使用cclientDC类的好处是该资源可以自动释放,而不用人工的释放
dc.MoveTo(m_SPoint);
dc.LineTo(m_EPoint);
}
}
}
void IRSData::Drawfirstderivate(int excelrows)
{
for(int er=0;er<excelrows-1;er++)
{
m_SPoint.x=(long)m_Firstderivate[er][0];
m_SPoint.y=600-(long)m_Firstderivate[er][1];
m_EPoint.x=(long)m_Firstderivate[er+1][0];
m_EPoint.y=600-(long)m_Firstderivate[er+1][1];
if(!m_EPoint.x==0)
{
CClientDC dc(AfxGetApp()->GetMainWnd());//使用cclientDC类的好处是该资源可以自动释放,而不用人工的释放
dc.MoveTo(m_SPoint);
dc.LineTo(m_EPoint);
}
}
}
void IRSData::Drawsecondderivate(int excelrows)
{
for(int er=0;er<excelrows-1;er++)
{
m_SPoint.x=(long)m_Secondderivate[er][0];
m_SPoint.y=600-(long)m_Secondderivate[er][1];
m_EPoint.x=(long)m_Secondderivate[er+1][0];
m_EPoint.y=600-(long)m_Secondderivate[er+1][1];
if(!m_EPoint.x==0)
{
CClientDC dc(AfxGetApp()->GetMainWnd());//使用cclientDC类的好处是该资源可以自动释放,而不用人工的释放
dc.MoveTo(m_SPoint);
dc.LineTo(m_EPoint);
}
}
}
在窗口类中定义了一个该类型的变量,光谱数值采用excel表形式导入(数据导入完全正确), 之后调用一阶求导函数firstderivate(), 再绘制到窗口中,结果发现绘制的图形只能绘制到第1010个数据点。在此数据点之后,求取的导数值基本上都是0,偶尔会出现一些非零值,在绘制图形时则完全绘制不出来。后半截的求导结果也存在问题。请高手指点错误在哪里?!