Conversion from mathematica to matlab

  • Mathematica
  • Thread starter ggeo1
  • Start date
  • #1
63
0

Main Question or Discussion Point

Hello,
i have the following problem in mathematica and i want to convert it in matlab ,but in 3 dimensions.

Code:
npoints = 10000;
vectorpoint := {RandomReal[{-1, 1}], RandomReal[{-1, 1}]}
experiment = Table[vectorpoint, {npoints}];
experiment[[10]]
the result is for example {-0.921607, -0.389386}

Now, in matlab (for 3d)

Code:
npoints = 10000;
v1=2*rand-1;
v2=2*rand-1;
v3=2*rand-1;
vectorpoint=[v1,v2,v3];
experiment=(vectorpoint:npoints);
experiment(10)
The problem is that the result is for example
9.9238 , a one dimension ,but i want 3d.

I can't figure how i must write it.
 

Answers and Replies

  • #2
63
0
Hello ,

I tried : experiment([10 10 10]) but it gives me : 8.6808 8.6808 8.6808
But it is supposed to be in the range (-1,1).

Any help?

EDIT----------------------------
Also,how can i do sth like this?

[x y z]=sqrt(1:3)

in order to be x=1 , y=1.4142 , z=1.7321


EDIT------------------------------
For the previous , i did this:

Code:
syms x y z
vec=[x y z]
new=sqrt(1:length(vec))

new=1.0000    1.4142    1.7321   (is there another way to do all this?)
EDIT:::

I also did this :

Code:
vector=[v1,v2,v3]
new=num2cell(vector)
[x,y,z]=new{:}
And finally,

if i name for example ,the previous statement , vector=[x y z]
How can i do this work? ezplot3(vector,'r')

I am new to matlab ( i have done some mathematica though)

Thanks!
 
Last edited:
  • #3
63
0
Hello,
I updated my code and now i am at this :

Code:
npoints=10000;
vectorpoint=2*rand(1,3)-1
for i=1:npoints
   2*rand(1,3)-1
    end
1) Is there another way to write this :
for i=1:npoints
2*rand(1,3)-1
end
in an one line?

2) I wrote in the loop 2*rand(1,3)-1 because if i write vectorpoint it will keep only one value of it.Is there a way to write vectorpoint and give me different values every time i call it?

If anyone can help...
 
  • #4
63
0
Ok, here is the solution

1) Just this : experiment=2*rand(npoints,3)-1

2) As for the vectorpoint,probably only with function
 

Related Threads for: Conversion from mathematica to matlab

Replies
7
Views
878
Replies
14
Views
9K
  • Last Post
Replies
2
Views
808
Replies
2
Views
4K
  • Last Post
Replies
7
Views
6K
Replies
1
Views
3K
  • Last Post
Replies
12
Views
1K
Top