Outputs for function in class method

8 次查看(过去 30 天)
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 个)

类别

Help CenterFile Exchange 中查找有关 App Building 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by