Can't set matlab class parameter
I created a (very first) Matlab class for storing image sequences.
When I apply a method to an instance of a class, no class attributes are set at all.
classdef sequence
%% Properties %%
properties
images;
width;
height;
end
%% Methods %%
methods
%% Constuctor %%
function obj = sequence()
obj.images = {};
obj.width = -1;
obj.height = -1;
end
%% Others methods %%
function numberOfImages = getNumberOfImages(obj)
numberOfImages = length(obj.images);
end
function addImage(obj, imageToAdd)
numberOfImages = obj.getNumberOfImages();
obj.images{numberOfImages + 1} = imageToAdd;
if numberOfImages == 0
[h, w] = size(imageToAdd);
obj.height = h;
obj.width = w;
end
end
function image = getImage(obj, i)
image = obj.images{i};
end
end
end
I followed the Matworks documentation closely, but I still don't know where my error is.
Here is the code I wrote to use my class:
%% Parameters %% imageFilename1 = '../Data/Test/1.png'; imageFilename2 = '../Data/Test/2.png'; alpha = 50; numberOfIterations = 50; %% Read images %% image1 = double(imread(imageFilename1)); image2 = double(imread(imageFilename2)); imageSequence = sequence(); imageSequence.addImage(image1); imageSequence.addImage(image2);
Where am I going wrong?
+3
source to share
1 answer
You are using a value class, so changes to the parameters do not change the actual object. To make it work, you must change the first line to:
classdef sequence < handle
Thus, you have created a descriptor class that you can use as you like.
For more information, you can check this page
+2
source to share