Code Monkey home page Code Monkey logo

Comments (4)

arokem avatar arokem commented on May 22, 2024

Hello! First of all, concerning the extra space in the in/out to the magic:
yes - it is somewhat finnicky and cares about white-space. This is because
the magic is doing some string handling of that line, and it's rather crude
(for example it simply splits on commas...). I have made a new issue to
improve this, but I am not sure when I will get around to dealing with
this.

Second - I see that you are working with the webserver version of the
bridge. We've made a lot of changes since 0.2, including support for
complex numbers. Do you know how to install pymatbridge from the
source-code available on github? If you pull the recent master and install
that, complex numbers should work for you. Please let me know if you need
help with the installation. We are hoping to make this easier, but it's
still a bit rough around the edges.

On Tue, May 13, 2014 at 3:18 PM, bs448c [email protected] wrote:

Hi

I'm trying to port a compressed sensing matlab example from
http://compsens.eecs.umich.edu/sensing_tutorial.php to iphton 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: [email protected]
% 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)
in ()
----> 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: [email protected]\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 (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

โ€”
Reply to this email directly or view it on GitHubhttps://github.com//issues/67
.

from python-matlab-bridge.

bs448c avatar bs448c commented on May 22, 2024

Hi, awesome, thanks for the quick reply. Indeed I should have version 0.2 (according to version.py .. is there a way of displaying the version in my ipynb?) as I have pip installed it using cygwin under Windows .. I will try to install it from source and report back. Thanks!!

from python-matlab-bridge.

arokem avatar arokem commented on May 22, 2024

As of about a minute ago, if you install from master, you should be able to
see something like:

In [*6*]: import pymatbridge


In [*7*]: pymatbridge.__version__

Out[*7*]: '0.3.dev'

On Tue, May 13, 2014 at 3:44 PM, bs448c [email protected] wrote:

Hi, awesome, thanks for the quick reply. Indeed I should have version 0.2
(according to version.py .. is there a way of displaying the version in my
ipynb?) as I have pip installed it in cygwin under Windows .. I will try
to install it from source and report back. Thanks!!

โ€”
Reply to this email directly or view it on GitHubhttps://github.com//issues/67#issuecomment-43022754
.

from python-matlab-bridge.

bs448c avatar bs448c commented on May 22, 2024

pymtbridge.__version__ doesn't work for v 0.2 but it does for 0.3-dev .. I managed to install it and can import, however

Python 2.7.6 |Anaconda 1.9.1 (64-bit)| (default, Nov 11 2013, 10:49:15) [MSC v.1
500 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 1.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import pymatbridge

In [2]: pymatbridge.__version__
Out[2]: '0.3.dev'

In [3]: %load_ext pymatbridge
Starting MATLAB on ZMQ socket tcp://127.0.0.1:55555
Send 'exit' command to kill the server
............................................................Matlab session timed
 out after 60 seconds
MATLAB failed to start

In [4]:

MATLAB Command Windows complains

MATLAB is running in headless mode.  Figure windows will not be displayed.

To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.

Invalid MEX-file 'C:\Users\Benjamin\Anaconda\lib\site-packages\pymatbridge\matlab\messenger.mexw64': The specified module could not be
found.

Error in matlabserver (line 7)
messenger('init', socket_address);

ยป 

This is clearly related to #56 .. libzmq.dll is in my PATH but I don't know how to compile the messenger myself ...

from python-matlab-bridge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.