Outputs for function in class method
17 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
HYZ
le 25 Oct 2022
Réponse apportée : Walter Roberson
le 25 Oct 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:
- if I can import mydata vector into methods like below. (I think I cannot use mydata just like this).
- 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 commentaire
Walter Roberson
le 25 Oct 2022
your class method makematrix must accept a class member as the first parameter, unless you make it a static method of the class.
Réponse acceptée
Walter Roberson
le 25 Oct 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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Basic Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!