How to detect the 'end' directive in subsref?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alex Kashuba
el 30 de En. de 2020
Comentada: Alex Kashuba
el 30 de En. de 2020
Hi all!
I am trying to reimplement the indexing of the object. Let us take as an example this primitive class that return the substript
classdef buffer
function value = subsref(obj, S)
value = S(1).subs{1};
end
end
Let's create object
buf=buffer()
Then buf(7) returns 7. buf(3:7) returns [3 4 5 6 7]. All good so far. Then buf(:) returns char ':'. Ok, can process that. Now comes the funny part:
buf(end) returns 1
buf(end+1) returns 2
buf(1:end) returns 1
buf(2:end) returns []
Question: is there a workaround so that 'end' is not always equivalent of 1, but I would be able to add my own implementation?
0 comentarios
Respuesta aceptada
Steven Lord
el 30 de En. de 2020
The reason end was always taking the value 1 is probably because your object is a scalar (size [1 1]) that internally contains an array. Consider overloading size to return the size of that internal array if appropriate.
Más respuestas (0)
Ver también
Categorías
Más información sobre Construct and Work with Object Arrays 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!