失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > MATLAB报错 Integers can only be raised to positive integral powers 是什么意思?

MATLAB报错 Integers can only be raised to positive integral powers 是什么意思?

时间:2024-03-19 09:36:32

相关推荐

MATLAB报错 Integers can only be raised to positive integral powers 是什么意思?

报错代码是下面这样的:

I=imread('pout.jpg');

if size(I,3)>1 %判断如果是彩色图像,转换为灰度图

I=rgb2gray(I);

end

Gamma_0_75=I.^(0.75);

"Integers can only be raised to positive integral powers."这句话翻译过来就是说整数的幂次只能是正整数~解决方法是把类型为uint8类型的矩阵转为double类型,将程度修改为下面这样就可正常运行了!

I=imread('pout.jpg');

if size(I,3)>1 %判断如果是彩色图像,转换为灰度图

I=rgb2gray(I);

end

I=double(I);

Gamma_0_75=I.^(0.75);

深层分析原因,为啥不能这样呢?原因是uint8只能存储整数类型的数据,如果你的幂含小数或是负数,那结果就不一定是整数了,所以不能这样写!

如果觉得《MATLAB报错 Integers can only be raised to positive integral powers 是什么意思?》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。