1

Using Python, I want to write a Matlab struct to disk. This is fairly simple using scipy.io module: http://docs.scipy.org/doc/scipy-0.9.0/reference/tutorial/io.html

However, I want one of the fields of the struct to be a function of the form @sqrt so that when I load the .mat file to disk in matlab, I get this functionality:

>> myStruct = load('MyStruct.mat')
>> myStruct.myFunction(5)
ans =
    2.2361

But I can't find how to do this. Simply putting in the string of '@sqrt' into one of the struct fields doesn't work.

thanks!

1 Answer 1

1

I've never worked with SciPy, but I can think of a possible workaround. Store the function name string instead of its handle, and in MATLAB use str2func:

myfunc = str2func(myStruct.myFunction);
myfunc(5)

If you really need a one-liner, you can use feval instead:

feval(myStruct.myFunction, 5)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.