Outputs for function in class method

조회 수: 7 (최근 30일)
HYZ
HYZ 2022년 10월 25일
답변: Walter Roberson 2022년 10월 25일
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
Walter Roberson
Walter Roberson 2022년 10월 25일
your class method makematrix must accept a class member as the first parameter, unless you make it a static method of the class.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2022년 10월 25일
  • 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개)

Community Treasure Hunt

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

Start Hunting!

Translated by