Outputs for function in class method

9 Ansichten (letzte 30 Tage)
HYZ
HYZ am 25 Okt. 2022
Beantwortet: Walter Roberson am 25 Okt. 2022
Hi,
I have a script with classdef and method. the below is the structure of the script.
I woud like to create mymatrix from this script which can be used as obj.loadthis (1,mymatrix) in the command window. so in the command,
load ('mydata.mat')
V = testing(a,b,c)
mymatrix = V.makematrix (Mydata);
V.loadthis(1, mymatrix);
I have two questions:
  1. if I can import mydata vector into methods like below. (I think I cannot use mydata just like this).
  2. how can I write so make 'mymatrix' to be used as input for the subsequent function.
thanks a lot in advance!
classdef testing < handle
properties
....
end
properties (Access = private)
...
end
methods
function obj = testing (a, b, c)
....
end
function mymatrix = makematrix (obj, mydata) %mydata vector was made from outside
temp = struct('cdata',[]);
for i = 1:60
Screen('DrawDots', obj.Window, mydata(:, :, i)',3, [255 255 255], [1920 1080], 0);
temp(frameIdx).cdata = Screen('GetImage', obj.Window);
end
mymatrix = double(cat(4,temp.cdata));
end
function loadthis(obj, VideoIndex, mymatrix)
...
end
end
end
  1 Kommentar
Walter Roberson
Walter Roberson am 25 Okt. 2022
your class method makematrix must accept a class member as the first parameter, unless you make it a static method of the class.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 25 Okt. 2022
  • if I can import mydata vector into methods like below. (I think I cannot use mydata just like this).
Yes, now that you have made obj a parameter to the method, the call you used should work.
  • how can I write so make 'mymatrix' to be used as input for the subsequent function.
You already did.
The way you wrote it is unusual. It would be much more common to have made mymatrix into a property of the class, and to not return it from the method, and to not pass it as a parameter to the loadthis() method since it would already be a property accessible through obj.

Weitere Antworten (0)

Kategorien

Mehr zu App Building 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!

Translated by