Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluating .m file taking string as input #15

Open
cgerlein opened this issue May 11, 2016 · 7 comments
Open

Evaluating .m file taking string as input #15

cgerlein opened this issue May 11, 2016 · 7 comments

Comments

@cgerlein
Copy link

Hi,

I have been trying to use teh matlab_wrapper as an alternative to the Engine, which for some obscure reason, just stopped working on me recently and I just haven't been able to fix it. I'm trying to evaluate a function that takes one input: a filename. Here is what I'm doing:

import matlab_wrapper
matlab = matlab_wrapper.MatlabSession(matlab_root='/Applications/MATLAB_R2015a.app/')
matlab.put('filename','/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir')
matlab.eval('loadsir')

At which point I get the following error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/matlab_wrapper/matlab_session.py", line 181, in eval
    raise RuntimeError("Error from MATLAB\n{0}".format(error_string))
RuntimeError: Error from MATLAB
MATLAB:minrhs: Not enough input arguments.
Error: in fuction loadsir in file /Users/cynthiagerlein/Dropbox (Personal)/Scatterometer/Matlab/loadsir.m line 143

My Matlab function definitely only takes one argument. Does it have something to do with the fact that it's a string...?

@grahamj1978
Copy link

You problem is mostly likely that you are not passing the variable to the function. Try matlab.eval('loadsir(filename)'). The eval command literally evaluates what you submit, so as far as it is concerned, you are trying to call the function without parameters.

@cgerlein
Copy link
Author

cgerlein commented May 12, 2016

Thanks, that makes sense. I was just blindly copying the example file, without realizing that it wasn't calling for an argument. I'm having trouble with the fact that the argument is a string: I tried all the combination of ' but it's not looking like any of them works:

matlab.eval('loadsir'('/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir'))
matlab.eval('loadsir(/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir)')
matlab.eval('loadsir'(/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir))
matlab.eval(loadsir('/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir'))

Both the function name and the argument have to be strings, which seems to confuse either the wrapper or Matlab, depending on the version... Any idea how to get around that problem?

@mrkrd
Copy link
Owner

mrkrd commented May 12, 2016

2016-05-12 03:46 +0200, Cynthia Gerlein-Safdi [email protected]:

Thanks, that makes sense. I was just blindly copying the example file, without realizing that it wasn't calling for an argument. I'm having trouble with the fact that the argument is a string: I tried all the combination of '' but it's not looking like any of them works:

matlab.eval('loadsir'('/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir'))
matlab.eval('loadsir(/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir)')
matlab.eval('loadsir'(/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir))
matlab.eval(loadsir('/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir'))

but none of it seems to work because both the function name and the argument have to be strings... Any idea how to get around that problem?

You could either properly escape the single quote characters, or use
double quotes as the external quotes, or do something like this:

matlab.put('filename', '/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir')
matlab.eval('loadsir(filename)')

I think that the last one is the preferable way. ;) Did it work?

Marek

@mrkrd
Copy link
Owner

mrkrd commented May 12, 2016

2016-05-12 10:18 +0200, [email protected]:

2016-05-12 03:46 +0200, Cynthia Gerlein-Safdi [email protected]:

Thanks, that makes sense. I was just blindly copying the example file, without realizing that it wasn't calling for an argument. I'm having trouble with the fact that the argument is a string: I tried all the combination of '' but it's not looking like any of them works:

matlab.eval('loadsir'('/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir'))
matlab.eval('loadsir(/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir)')
matlab.eval('loadsir'(/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir))
matlab.eval(loadsir('/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir'))

but none of it seems to work because both the function name and the argument have to be strings... Any idea how to get around that problem?

You could either properly escape the single quote characters, or use
double quotes as the external quotes, or do something like this:

matlab.put('filename', '/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir')
matlab.eval('loadsir(filename)')

I think that the last one is the preferable way.

This is also what @grahamj1978 pointed out. Thanks!

@cgerlein
Copy link
Author

cgerlein commented May 12, 2016

Hey,
Actually, no this last solution did not work either: I don't get an error, but the code just don't seem to run, probably because it's taking 'filename' as the filename. What did work though is the following:
img = matlab.workspace.loadsir('/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir')
found HERE and apparently posted by you! Does it make sense?

@mrkrd
Copy link
Owner

mrkrd commented May 16, 2016

2016-05-12 14:13 +0200, Cynthia Gerlein-Safdi [email protected]:

Hey,
Actually, no this last solution did not work either: I don't get an error, but the code just don't seem to run, probably because it's taking 'filename' as the filename. What did work though is the following:
img = matlab.workspace.loadsir('/Volumes/Cynthia_ExtHD_2TB/Scatterometer/Amazon/Amazon_Quickscat_SIR_Data/queh-a-Ama00-001-004.sir')
found HERE.
Does it make sense?

Yes, using matlab.workspace is an alternative way to call MATLAB functions.

However, I'm still surprised that the other method (matlab.put('name',
'/foo/bar.ext'); matlab.eval('loadsir(name)')) did not work. Could you
send me a simplified version of loadsir.m that illustrates the issue?
The simplified loadsir() does not have to do anything: just take a
string as input and fail -- I would like to replicate your problem.

Thank you!

Marek

@cgerlein
Copy link
Author

Hello Marek,

The loadsir.m file is actually available here: ftp://ftp.scp.byu.edu/pub/software/matlab/loadsir.m. It calls a bunch of other functions that are in that same matlab folder if you want to just try with the whole thing. An example file can be downloaded directly from here: ftp://ftp.scp.byu.edu/data/qscat/1999/sir/queh/SAm/201/a/queh-a-SAm99-201-204.sir.gz. You need to unzip it first, loadsir.m needs a .sir file.

The matlab.workspace option worked perfectly by the way, and I was so happy with how easy it was to install the matlab_wrapper. Great job!

Let me know if you reproduce the error.

Cynthia

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants