identity for a matrix cell
2 views (last 30 days)
Show older comments
Hello,
I would like to create an identity for a matrix cell
Something like:
x=A{2,1}
so that I can access A{2,1} with x
>> x=A{2,1}
x =
5
A{2,1} =
5
further on x is supposed to change continiously
x=x{2,1} is A{2,1}{2,1}
x=x{2,1} is A{2,1}{2,1}{2,1}
and so on
is that somehow possible
0 Comments
Accepted Answer
Guillaume
on 17 Jun 2015
That type of variable is called a reference. It is not available in matlab, so no it's not possible.
You could emulate it after a fashion with a class but the syntax would be awkward. The interface would have to be something like:
x = cellreference('A', 2, 1); %create reference to cell {2, 1} of A
x.set(5); %set value of referenced cell to 5
x.get; %get value of referenced cell
Under the hood, it would have to use evalin or similar. It's not going to be fast.
2 Comments
Guillaume
on 17 Jun 2015
cellreference would be a class that you would have to write yourselves, it's not something that comes with matlab.
I was just showing the syntax you would have to use with this hypothetical class. As the syntax is awkward and actually writing the set function is far from trivial (the get is easy), I don't see the benefit of it.
So for all intent and purpose, references in matlab are not possible.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!