Borrar filtros
Borrar filtros

Outputs for function in class method

11 visualizaciones (últimos 30 días)
HYZ
HYZ el 25 de Oct. de 2022
Respondida: Walter Roberson el 25 de Oct. de 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 comentario
Walter Roberson
Walter Roberson el 25 de Oct. de 2022
your class method makematrix must accept a class member as the first parameter, unless you make it a static method of the class.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de Oct. de 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.

Más respuestas (0)

Categorías

Más información sobre App Building en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by