Subsref question using braces '{}' type and a char subs
Mostrar comentarios más antiguos
Hello, I am implementing subsref in my class for dealing with braces, '{}'. I want to be able to call
>> classname{'chars'}
but all I get is an error:
??? Error using ==> subsref
Too many output arguments.
The debugger never even gets into the subsref function for me to see whats happening. If I use the same logic but for '()' type indexing, it works fine. Similarly, if I use '{}' but with a number I can get the code to to into the subsref, but I need to be able to use '{}' with char subs not a number/index.
Here is the switch case for the '{}' type
switch s(1).type
case '{}'
v = obj.variable(s(1).subs);
if length(s) == 2
B = v.data(s(2).subs);
elseif length(s) == 3
switch s(3).subs
case data
B = v.data(s(2).subs);
case grid
B = v.grid(s(2).subs);
end
else
B = v;
end
10 comentarios
Walter Roberson
el 25 de Feb. de 2011
Question: are data and grid defined variables? If not then perhaps they should be coded as 'data' or perhaps even {{'data'}} ? (If they _are_ defined variables then you have a name conflict with the function grid())
Alexander
el 28 de Feb. de 2011
Walter Roberson
el 28 de Feb. de 2011
Note that when you code
case data
then Matlab will evaluate data and try to match the result against s(3).subs . Is that what you want, or in that context are you intending data to be a constant such as 'data' ?
Alexander
el 28 de Feb. de 2011
Alexander
el 28 de Feb. de 2011
Walter Roberson
el 28 de Feb. de 2011
I speculate that possibly you might find something interesting if you put a default case in for the type and display the type there.
Alexander
el 28 de Feb. de 2011
Alexander
el 28 de Feb. de 2011
Walter Roberson
el 28 de Feb. de 2011
I am hypothesizing that for some reason the type is not matching '{}'
Perhaps I have misunderstood. Are you indicating that you have demonstrated that it never reaches the switch s(1).type code? Or is it possible that that switch is executed but '{}' is not what is in s(1).type ?
Alexander
el 28 de Feb. de 2011
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Customize Object Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!