How to translate the following code from Mathematica to Matlab?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Eric
el 30 de Ag. de 2014
Editada: Andrei Bobrov
el 2 de Sept. de 2014
I need to construct a matrix similar to the following:
l = 2; m = 4; Table[(2 x - y*l)/m, {x, 0, 5}, {y, 0, 5}] // MatrixForm
How can I do that in Matlab?
0 comentarios
Respuesta aceptada
Eric
el 1 de Sept. de 2014
Editada: Eric
el 1 de Sept. de 2014
4 comentarios
Image Analyst
el 1 de Sept. de 2014
You're welcome. By the way, I think I should have gotten the credit/points for the answer (the official "Accept") since I was the one who answered your original posted question. Oh well, maybe on your next question.
Más respuestas (3)
Image Analyst
el 30 de Ag. de 2014
Try this:
c = 0:.5:2.5;
r = -c;
toeplitz(c,r)
3 comentarios
Image Analyst
el 30 de Ag. de 2014
There is no way to construct a given matrix from a general purpose universal function. For example, this second matrix you gave will require a different function. If you specify a function, then you can build an output matrix. But if you specify an output matrix, then you're done. No need to find some function to generate it because you already have it.
Image Analyst
el 31 de Ag. de 2014
Of course you can translate Mathematica code. You can learn how to write functions in MATLAB. I suggest you look at this http://www.mathworks.com/matlabcentral/answers/8026-best-way-s-to-master-matlab
Guillaume
el 30 de Ag. de 2014
Editada: Guillaume
el 30 de Ag. de 2014
There isn't a function in matlab to directly construct a matrix as in your examples but you could replicate it with meshgrid and arrayfun.
I don't know anything about mathematica but it looks like x and y (or m and l in your latest example) represent row and column inputs so:
l = 2; m = 4;
[y x] = meshgrid(0:5, 0:5);
t = arrayfun(@(xx, yy) (2*xx-yy*l)/m, x, y);
3 comentarios
Image Analyst
el 31 de Ag. de 2014
There's no one function that will generate any arbitrary matrix he happens to toss out there. He can write a function but the function will be whatever he says it will be. And if he tosses out some arbitrary Mathematica code, then it will have to be translated "custom" for whatever code he specifies.
Andrei Bobrov
el 1 de Sept. de 2014
Editada: Andrei Bobrov
el 2 de Sept. de 2014
l = 2:10;
m = 1:5;
idx = bsxfun(@eq,l(:),m(:)');
MatrixForm = idx + 0;
k = intersect(l,m);
a = 1;
b = 100;
MatrixForm(idx) = 1./(a*((b - 1)*k)./((b + 1)*k + 1));
first answer:
Wolfram Mathematica:
l = 2;
m = 4;
Table[(2 x - y*l)/m, {x, 0, 5}, {y, 0, 5}] // MatrixForm
Matlab:
l = 2;
m = 4;
out = bsxfun(@minus,2*(0:5)',(0:5)*l)/m;
0 comentarios
Ver también
Categorías
Más información sobre Number Theory en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!