Unable to assign values to some matrix-cells

2 views (last 30 days)
Hi, I'm currently trying to assign values in a matrix defined in a class. My problem is that the last row and last column values stay unchanged... When 'debugging' I can see that they are well traveled in the for-loop.
Thank you in advance for any suggestion.
Here is a screenshot of my matrix:
And the different pieces of code that can be useful
E = Ez(1, 5);
for x=-2:2
for y=-2:2
E.set(x,y,1,0);
end;
end;
class Ez:
classdef Ez < handle
properties
total_timestamps
matrices
end;
methods
function obj = Ez(total_timestamps, dimensions)
obj.total_timestamps = total_timestamps;
for i=1:total_timestamps
obj.matrices{i} = field(dimensions+(total_timestamps-i)*2);
end;
end;
function obj = set(obj, x,y,z,t)
if(t >= 0)
obj.matrices{t+1}.set(x,y,z);
end;
end;
end;
end
class field:
classdef field < handle
properties
width;
height;
values;
end;
methods
function obj = field(varargin)
if(nargin == 1)
obj.width = varargin{1};
obj.height = varargin{1};
obj.values = zeros(varargin{1});
else
obj.width = varargin{1};
obj.height = varargin{2};
obj.values = zeros(varargin{2},varargin{1});
end;
end;
function obj = set(obj, x,y,z)
actual_x = obj.toActualX(x);
actual_y = obj.toActualY(y);
if actual_x < obj.width && actual_x > 0 && actual_y < obj.height && actual_y > 0
obj.values(actual_y,actual_x) = z;
end;
end;
end;
methods(Access = private)
function actual_x = toActualX(obj,x)
if(mod(obj.width,2) ~= 0)
actual_x = (obj.width+1)/2 + x;
else
actual_x = obj.width/2 +1 + x;
end;
end
function actual_y = toActualY(obj,y)
if(mod(obj.height,2) ~= 0)
actual_y = (obj.height+1)/2 + y;
else
actual_y = obj.height/2 +1 + y;
end;
end
end;
end

Accepted Answer

Image Analyst
Image Analyst on 23 Nov 2013
Try <= :
if actual_x <= obj.width && actual_x > 0 && actual_y <= obj.height && actual_y > 0

More Answers (0)

Categories

Find more on Argument Definitions in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!