Unrecognized function or variable 'x'

조회 수: 11 (최근 30일)
paul_dak
paul_dak 2020년 11월 8일
댓글: per isakson 2020년 11월 9일
classdef Rat <handle
properties
image = imread('rat_single.tif')
location
speed = 5
direction = 30
end
methods
function obj = Rat(loc)
if nargin == 1
obj.location = loc;
else
obj.location = [0,0];
end
end
function im = get_image(self)
im = imrotate_w(self.image, self.direction);
end
function vectors = mouse_vec(self,im)
global MAX_SPEED;
multiply_factor = 7;
im_cntr = get_image_center(im);
x_move = cos(self.direction);
y_move = sin(self.direction);
vect_move = [x_move,y_move] * (MAX_SPEED * multiply_factor);
start_vect = im_cntr;
vectors = [start_vect,vect_move];
end
function plot_rat(self)
rotd_im = imrotate_w(self.image,self.direction);
imshow(rotd_im);
axis on
hold on;
vectors = mouse_vec(self,rotd_im);
quiver(vectors(1),vectors(2),vectors(3),vectors(4));
end
end
methods (Static)
function rot_im = imrotate_w(im, d)
if((nargin ~= 2) || ndims(im) == 3)
disp('Wrong number of parameters, or their contents. Exiting...');
return;
end
max_val = max(im(:));
rot_im = max_val - imrotate(max_val - im, d);
plot(rot_im);
end
function center = get_image_center(im)
info = size(im);
xR = info(1);
yR = info(2);
center_x = floor(xR/2);
center_y = floor(yR/2);
center = [center_x,center_y];
end
end
end
the error i get:
Unrecognized function or variable 'get_image_center'.
Error in Rat/mouse_vec (line 44)
im_cntr = get_image_center(im); %finding the center of the image
Error in Rat/plot_rat (line 58)
vectors = mouse_vec(self,rotd_im);
Error in test_rat (line 3)
plot_rat(steve);
>>
ignore the line numbers, these are not correct.
do you have any idea? it tried so many things.
im calling plot_rat from another file in the same dir.
Thank you!

답변 (1개)

per isakson
per isakson 2020년 11월 8일
편집: per isakson 2020년 11월 8일
"Unrecognized function or variable 'get_image_center'."
Replace
im_cntr = get_image_center(im);
by
im_cntr = self.get_image_center(im);
or
im_cntr = Rat.get_image_center(im);
And replace
rotd_im = imrotate_w(self.image,self.direction);
by
rotd_im = self.imrotate_w(self.image,self.direction);
and plot(rot_im); by imshow(rot_im);
See: Debug a MATLAB Program. "the error i get:" It would be helpful if you show how you get them.
  댓글 수: 2
paul_dak
paul_dak 2020년 11월 8일
편집: per isakson 2020년 11월 9일
Thank you it works!
i replaced
im_cntr = get_image_center(im);
with
im_cntr = self.get_image_center(im);
but i dont understand why it is needed, get_image_center is static
per isakson
per isakson 2020년 11월 9일
"but i dont understand why it is needed" The simple answer: Matlab is designed that way. Matlab could have been designed as you took for granted.
"get_image_center is static" That makes it possible to use im_cntr = Rat.get_image_center(im);

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

카테고리

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

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by