-
Notifications
You must be signed in to change notification settings - Fork 96
Open
Description
Hi
I'm trying to port a compressed sensing matlab example from http://compsens.eecs.umich.edu/sensing_tutorial.php to ipython notebook / pymatbridge.
I've noticed some strange behaviour of passing arguments back and forth which I think causes me trouble in my port.
import pymatbridge as pymat
ip = get_ipython()
pymat.load_ipython_extension(ip)
Starting MATLAB on http://localhost:53257
visit http://localhost:53257/exit.m to shut down same
....MATLAB started and connected!
so far so good .. but now it gets weird
%%matlab -i a -o b,c
b = a + 3
c = b + 3
b =
4 5 6
c =
7 8 9
while this makes sense .. that doesn't:
%%matlab -i a -o b, c
b = a + 3
c = b + 3
cb =
4 5 6
c =
7 8 9
note the additional blank in passing the -o, and the altered variable name in the output of matlab.
Related or not, here's my attempt on the port which fails when I try to pass back a (complex) array:
%%matlab -o xf
%Author: Osama Ullah Khan,
% Phd Student, University of Michigan-Ann Arbor.
% Email: oukhan@umich.edu
% Version: 1.0
%
%This code demonstrate compressive sensing example. In this
%example the signal is sparse in frequency domain and random samples
%are taken in time domain.
close all;
clear all;
%setup path for the subdirectories of l1magic
path(path, 'C:\MATLAB\R2013a\l1magic\Optimization');
path(path, 'C:\MATLAB\R2013a\l1magic\Data');
%length of the signal
N=1024;
%Number of random observations to take
K=128;
%Discrete frequency of two sinusoids in the input signal
k1=29;
k2=34;
k3=39;
n=0:N-1;
%Sparse signal in frequency domain.
x=sin(2*pi*(k1/N)*n)+sin(2*pi*(k2/N)*n)+sin(2*pi*(k3/N)*n);
xf=fft(x);
which gives me
---------------------------------------------------------------------------
SystemError Traceback (most recent call last)
<ipython-input-10-b7fe87abb3ba> in <module>()
----> 1 get_ipython().run_cell_magic(u'matlab', u'-o xf', u"\n%Author: Osama Ullah Khan,\n% Phd Student, University of Michigan-Ann Arbor.\n% Email: oukhan@umich.edu\n% Version: 1.0\n%\n%This code demonstrate compressive sensing example. In this\n%example the signal is sparse in frequency domain and random samples\n%are taken in time domain.\n\nclose all;\nclear all;\n\n%setup path for the subdirectories of l1magic\npath(path, 'C:\\MATLAB\\R2013a\\l1magic\\Optimization');\npath(path, 'C:\\MATLAB\\R2013a\\l1magic\\Data');\n\n\n%length of the signal\nN=1024;\n\n%Number of random observations to take\nK=128;\n\n%Discrete frequency of two sinusoids in the input signal\nk1=29;\nk2=34;\nk3=39;\n\nn=0:N-1;\n\n%Sparse signal in frequency domain.\nx=sin(2*pi*(k1/N)*n)+sin(2*pi*(k2/N)*n)+sin(2*pi*(k3/N)*n);\n\nxf=fft(x);")
C:\Users\Benjamin\Anaconda\lib\site-packages\IPython\core\interactiveshell.pyc in run_cell_magic(self, magic_name, line, cell)
2127 magic_arg_s = self.var_expand(line, stack_depth)
2128 with self.builtin_trap:
-> 2129 result = fn(magic_arg_s, cell)
2130 return result
2131
C:\Users\Benjamin\Anaconda\lib\site-packages\pymatbridge\matlab_magic.pyc in matlab(self, line, cell, local_ns)
C:\Users\Benjamin\Anaconda\lib\site-packages\IPython\core\magic.pyc in <lambda>(f, *a, **k)
189 # but it's overkill for just that one bit of state.
190 def magic_deco(arg):
--> 191 call = lambda f, *a, **k: f(*a, **k)
192
193 if callable(arg):
C:\Users\Benjamin\Anaconda\lib\site-packages\pymatbridge\matlab_magic.pyc in matlab(self, line, cell, local_ns)
296 for output in ','.join(args.output).split(','):
297 self.shell.push({output:self.matlab_converter(self.Matlab,
--> 298 output)})
299 else:
300 raise RuntimeError(no_io_str)
C:\Users\Benjamin\Anaconda\lib\site-packages\pymatbridge\matlab_magic.pyc in matlab_converter(matlab, key)
115 maxtime=matlab.maxtime)
116
--> 117 return loadmat('%s/%s.mat'%(tempdir, key))
118
119
C:\Users\Benjamin\Anaconda\lib\site-packages\pymatbridge\matlab_magic.pyc in loadmat(fname)
71 if isinstance(f[var_name], h5py.Dataset):
72 # Currently only supports numerical array
---> 73 data = f[var_name].value
74 if len(data.dtype) > 0:
75 # must be complex data
C:\Users\Benjamin\Anaconda\lib\site-packages\h5py\_hl\dataset.pyc in value(self)
174 DeprecationWarning("dataset.value has been deprecated. "
175 "Use dataset[()] instead.")
--> 176 return self[()]
177
178 @property
C:\Users\Benjamin\Anaconda\lib\site-packages\h5py\_hl\dataset.pyc in __getitem__(self, args)
437 mspace = h5s.create_simple(mshape)
438 fspace = selection._id
--> 439 self.id.read(mspace, fspace, arr, mtype)
440
441 # Patch up the output for NumPy
SystemError: error return without exception set
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels