Error using ones Size inputs must be integers?

조회 수: 1 (최근 30일)
youb mr
youb mr 2019년 11월 19일
댓글: Walter Roberson 2020년 3월 17일
hello every one i have a problem with my code for error
r =[zeros(size(img2,1),size(img2,2)) ones(size(img2,1),size(img2,2)/2)];
where img2 an image of size (111 235)
Error using ones
Size inputs must be integers
and i want to have an image of the same size of img2

채택된 답변

Walter Roberson
Walter Roberson 2019년 11월 19일
If you want an image the same size as img2 then
r = zeros(size(img2), class(img2));
after which you can assign ones into an appropriate section of r
Your phrase size(img2,2)/2 has a problem when the number of columns in img2 is odd, as it does happen to be. 235/2 is not an integer.
r(round(end/2)+1:end, round(end/2)+1:end) = 1; %perhaps
  댓글 수: 10
vishnu vvs
vishnu vvs 2020년 3월 17일
hi everyone in my code i have an error please help me out
Error using zeros
size inputs must be integers.
error in two _stage _sub
Q_phase = zeros (Nr,1) ;
ERROR IN main_SR
[AP1,DP1,p0] = two_stage_sub(H,K,bit,p);
Walter Roberson
Walter Roberson 2020년 3월 17일
You might have computed Nr using floating point arithmetic such as 0.35/0.001. If so... Don't Do That! Floating point computations are only approximate when decimal fractions are used.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by