Getting an error: Error using .* Integers can only be combined with integers of the same class, or scalar doubles.

1 次查看(过去 30 天)
After running the following code I am getting this error in the pol2cart function
[srad,sang,S] = specxture(f);
function [ srad, sang, S] = specxture( f )
S = fftshift(fft2(f));
%imtool (S);
S = abs(S);
%imshow(S,[]);
[M, N] = size(S);
x0 =uint8(M/2+1);
%x0=int16(x0);
y0 =uint8(N/2+1);
%y0=int16(y0);
rmax = uint8((min(M, N)/2)-1);
%rmax1=int16(rmax);
srad = zeros(1, rmax);
srad(1) = S(x0, y0);
%imtool (S);
for r = 2:rmax
[xc, yc] = halfcircle(r, x0, y0);
srad(r) = sum(S(sub2ind(size(S), xc, yc)));
end
[xc, yc] = halfcircle(rmax, x0, y0);
sang = zeros(1, length(xc));
for a = 1:length(xc)
[xr, yr] = radial(x0, y0, xc(a), yc(a));
sang(a) = sum(S(sub2ind(size(S), xr, yr)));
end
S = mat2gray(log(1+S));
end
function [xc, yc] = halfcircle(r, x0, y0)
theta = 91:270;
theta = double(theta*pi/180);
[xc, yc] = pol2cart(theta, r);
xc = round(xc)'+x0;
yc = round(yc)'+y0;
function [x,y,z] = pol2cart(th,r,z)
x = r.*cos(th);
y = r.*sin(th);

采纳的回答

Walter Roberson
Walter Roberson 2018-11-27
You define rmax as uint8 . Your for loop with rmax as upper bound then becomes uint8 . You are passing that r to halfcircle and passing that uint8 to pol2cart along with the vector of double for theta. The operation of pol2cart involves r.*cos(theta) . With theta being a vector of double this becomes uint8 .* vector of double . That operation is not defined.
The workaround is to loop the pol2cart so that you pass in only a scalar theta as combining uint8 and scalar double is defined . You would then get out the x and y calculated in uint8 that you seem to be looking for.
  3 个评论
Walter Roberson
Walter Roberson 2018-11-27
I admit to being puzzled as to why you are using uint8 operations; it makes your calculation more difficult for no obvious benefit. I would have suggested, for example, changing
x0 =uint8(M/2+1);
to
x0 = floor(M/2+1);
and likewise for the others, and then just gone ahead with double.

请先登录,再进行评论。

更多回答(1 个)

D Aghor
D Aghor 2018-11-28
编辑:D Aghor 2018-11-28
As a part of my base paper implementation I am using this ''specxture'' function as it is from an Image Processing Text book.

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by