假设我有一个字符串str2double
,我想将其转换为double,
我正在尝试使用:
vnl_vector<double> distances;
for(int i=0; i<volumeSize[0]; i++){
std::cout<<"."<<std::flush;
for(int j=0; j<volumeSize[1]; j++){
for(int k=0; k<volumeSize[2]; k++){
double voxel[3];
voxel[0] = i*scale[0]*resolution + volumeOrigin[0];
voxel[1] = j*scale[1]*resolution + volumeOrigin[1];
voxel[2] = k*scale[1]*resolution + volumeOrigin[2];
double distance = maxDistance;
for(int plane=0; plane<volumeImageStack.size(); plane++){
double d = imagePlaneStack.at(plane)->DistanceToPlane(voxel);
if(d<distance)
distance = d;
}
distances.push_back(distance);
}
但是s的值变为128.我希望besselj(1,x)
函数将小数点识别为数字的一部分。
有什么办法吗?
提前致谢
答案 0 :(得分:3)
str2double
符合您的期望。输入whos news
或class(news)
,您会看到变量news
的类型为double
:
>> class(news)
ans =
double
(您可以使用str2num
获得相同的结果:news = str2num(s);
也会返回double
。)
你看到的事实
>> news =
128
没有小数点只是表示的问题。 的数字类型为double
,而128
当然与128.0
相同。