[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Need test for handles to classdef methods run in Matlab
From: |
John W. Eaton |
Subject: |
Re: Need test for handles to classdef methods run in Matlab |
Date: |
Sun, 24 Mar 2019 01:34:19 -0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 |
On 3/23/19 5:31 AM, PhilipNienhuis wrote:
Matlab r2019a prerelease:
format compact
obj = mycls ();
fh = @obj.meth;
fh(2)
meth
varargin =
1×2 cell array
{1×1 mycls} {[2]}
fh = @obj.smeth;
fh (2)
smeth
varargin =
1×1 cell array
{[2]}
Thanks.
Now I need to know one more thing. In expressions like the ones shown
above, is the value of obj captured when the function handle is created,
or is it just a name that is used for lookup later? To test that, maybe
the following will give some clue. If you define the additional function
function [fh1, fh2] = foo ()
obj = mycls ();
fh1 = @obj.meth;
fh2 = @obj.smeth;
end
and then execute
clear all
[fh1, fh2] = foo ();
fh1 (1)
fh2 (2)
what happens? Another test:
clear all
obj = mycls ();
fh1 = @obj.meth;
fh2 = @obj.smeth;
clear obj
fh1 (1)
fh2 (2)
Could someone run these tests in a recent version of Matlab and report
the results here? I'm attaching mycls.m and foo.m to this message.
jwe
foo.m
Description: Text Data
mycls.m
Description: Text Data