Hi list, I'd like to import into pd a matrix processed in matlab. Is it easy ? I've been trying to : If I type "save mymatrix matrix" within a matlab script, it saves a file : matrix.m If I want to read this file within pd and the zexy external lib, I can send a read message
but the file format seems to be different in zexy (the extension is .mtx), and pd doesn't accept it. What is the correct way to import a matrix ? thanks a lot.
François Bardet 10 place Thomas F-63000 Clermont-Ferrand 0033 4 73 92 50 80
Faites un voeu et puis Voila ! www.voila.fr
erm, saving that way will create binary MAT files. so you will need to save it using 'save tester.mtx my_matrix -ascii', then open it up in a text editor (eg. notepad) and manually append a line (I mean put this following line as the first line in the file):
matrix n m
where n is the number of columns and m is the number of rows (at least, from a rudimentary check, Matlab and zexy seem to order the row/column numbers the opposite way around, though I may well be wrong).
Something like that, anyway.
Matt
-=-=-=-=-=-=-=-=-=-=-=- http://www.loopit.org -=-=-=-=-=-=-=-=-=-=-=- ----- Original Message ----- From: f.bardet@voila.fr To: pd-list@iem.at Sent: Wednesday, February 02, 2005 4:36 PM Subject: [PD] matlab to pd
Hi list, I'd like to import into pd a matrix processed in matlab. Is it easy ? I've been trying to : If I type "save mymatrix matrix" within a matlab script, it saves a file : matrix.m If I want to read this file within pd and the zexy external lib, I can send a read message
but the file format seems to be different in zexy (the extension is .mtx), and pd doesn't accept it. What is the correct way to import a matrix ? thanks a lot.
François Bardet 10 place Thomas F-63000 Clermont-Ferrand 0033 4 73 92 50 80
Faites un voeu et puis Voila ! www.voila.fr
matthew jones wrote:
erm, saving that way will create binary MAT files. so you will need to save it using 'save tester.mtx my_matrix -ascii', then open it up in a text editor (eg. notepad) and manually append a line (I mean put this following line as the first line in the file):
matrix n m
where n is the number of columns and m is the number of rows (at least, from a rudimentary check, Matlab and zexy seem to order the row/column numbers the opposite way around, though I may well be wrong).
Something like that, anyway.
It should be pretty trivial to write a function in matlab that can do all this automatically including transposing the matrix if necessary.
Jonny www.jeremah.co.uk
matthew jones wrote:
matrix n m
where n is the number of columns and m is the number of rows (at least, from a rudimentary check, Matlab and zexy seem to order the row/column number
well, i learned at school that the order is always row column. this is how zexy's matrix is implemented. for the rest i tried to stay as compatible with matlab (or rather: octave) as possible.
the only thing that is sometimes confusing is the way, [matrix~] works. in literature, multiplying a signal-vector with a matrix is normally written as: M * s^ = p^ ("^" meaning "vector", capital letter indicating matrix)
[matrix~] however does
s^ * L = p^ (this seemed logical to me when looking at the inlets of the object)
mfg.asd.ea IOhannes
Hi François,
f.bardet@voila.fr wrote:
Can zexy lib process 3D matrices ? (I mean matrices with 3 indices,
e.g. a 10x8x3 matrix)
I don't know any details about zexy. Although, here is an idea, how to handle every N-dimensional matrix as a linear vector:
To convert a matrix to a vector in Matlab use:
linvec = reshape(matrix, [],1);
which will reshape the matrix to a linear vector.
To access any single element you have to recalculate the index:
indexlin = k + K*l + K*L*m + K*L*M*n + ...
with:
By the way: this is more native way to treat matrices in computational processing, because every matrix is stored in the RAM in the linear order in any case :-) That's why your more-dimensional index is recalculated to a linear index by every software which handles matrices.
regards, Piotr Majdak