MYM and fields name '_key'

With many thanks again to the author of MYM! We use it heavily in a production environment on a number of Matlab licenses and machine types.
Recently an issue has cropped up that cannot have affected us only, although we get no matches on searches at this site.
One of our main (and elderly) tables uses a Primary Key (auto-incrementing) with the name '_key'. This seems to be a common database technique. However, Matlab does not allow variable names that start with an underscore! Thus the MYM query works perfectly and returns the struct with member _key in it. And Matlab displays this variable ok, ie:
quakeDump =
_key: [2179x1 double]
time: {2179x1 cell}
latitude: [2179x1 double]
longitude: [2179x1 double]
Yet any attempt to operate on this field gets us:
??? Error: File: blah.m Line: 42 Column: 11
The input character is not valid in MATLAB statements or expressions.
There must be some simple work-around we are missing? So far though, the only ways out we see include:
1. Rename field from '_key' to 'key", etc. Problem: impacts hundreds of lines of existing code, and we'll never hear the end of it!
2. Revert to our pre-MYM technique and use a PERL-DBI script to access the database. Problem: Slower than frozen molasses!
Does anybody have any suggestions? THANKS ALOT!
- Clark

1 comentario

Walter Roberson
Walter Roberson el 17 de Mayo de 2012
Jan has a work around for this, but I never remember the keywords for searching for it.

Iniciar sesión para comentar.

 Respuesta aceptada

Jan
Jan el 17 de Mayo de 2012

0 votos

You can access ugly fieldnames using "dynamic fieldnames":
S.('_key')
or
key = '_key';
S.(a)

1 comentario

Clark
Clark el 17 de Mayo de 2012
Jan!
Thanks alot! That FIXED it. Since I can't thank you personally, then the best I can do is to say 'nice pic!'

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 17 de Mayo de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by