Unrecognized function or variable 'x'
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Antworten (1)
per isakson
am 8 Nov. 2020
Bearbeitet: per isakson
am 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);
2 Kommentare
per isakson
am 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);
Siehe auch
Kategorien
Mehr zu Whos finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!