Convert arguments in a function call to string, as written

11 views (last 30 days)

I'm writing a client for a web database that stores array like data, and I'd like to provide a proxy methods that can access data with a matlab array like indexing. Currently I do this by creating a struct with anonymous function member variables that take indeces as a string. For instance:

my_data.my_var('1:end') or my_data.my_var('2:3:22')

Ideally, I'd like to pass in a native range (getting rid of the single quotes), but I don't see how I can prevent the range from expanding before I can convert it to string inside the anonymous function body. Am I overlooking a way I can automatically convert the argument pass to a function directly into a string exactly as it was entered? Is the situation any better with a class method?

Accepted Answer

Walter Roberson
Walter Roberson on 19 Apr 2018

"Am I overlooking a way I can automatically convert the argument pass to a function directly into a string exactly as it was entered?"

Yes. You can use dbstack() to find out the file name and line number of the calling routine, and then you can parse through the source code of that function to determine exactly how it was entered.

This is, of course, wonky. And will not work for the command line.

Short of that, the best you can do is try to recreate the range string by examining the values, working out differences and how long each sub-trend lasts, and so on. People have posted code for that in the past (I have, at some point) but it might not be easy to find.

But if you want handle end, you are going to need to use objects and see https://www.mathworks.com/help/matlab/matlab_oop/object-end-indexing.html

More Answers (0)

Categories

Find more on Data Type Conversion 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!