MYM and fields name '_key'
2 views (last 30 days)
Show older comments
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 Comment
Walter Roberson
on 17 May 2012
Jan has a work around for this, but I never remember the keywords for searching for it.
Accepted Answer
Jan
on 17 May 2012
You can access ugly fieldnames using "dynamic fieldnames":
S.('_key')
or
key = '_key';
S.(a)
More Answers (0)
See Also
Categories
Find more on Database Toolbox 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!