Unrecognized function or variable 'x'

1 view (last 30 days)
paul_dak
paul_dak on 8 Nov 2020
Commented: per isakson on 9 Nov 2020
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!

Answers (1)

per isakson
per isakson on 8 Nov 2020
Edited: per isakson on 8 Nov 2020
"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 Comments
paul_dak
paul_dak on 8 Nov 2020
Edited: per isakson on 9 Nov 2020
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 on 9 Nov 2020
"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);

Sign in to comment.

Categories

Find more on Software Development Tools in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!