use pol2cart with not equal arguments

Hello all
Is it possible to use the pol2cart(THETA,RHO,Z) command if the vectors THETA and RHO are not equally sized and, as a result, matrix Z is not square? In my calculations, the THETA vector has 100 elements and the RHO vector has 1024 elements (so Z is 1024x100). If I increase the elements of THETA, then my program will take too long to finish (almost 8 days!).
Any help would be appreciated! Thank you all!
Antigoni

 Accepted Answer

tic
[rr, thth] = meshgrid(1:100,1:1024);
[x,y] = pol2cart(rr,thth);
toc
Taking a few thousanths of a second on my laptop.

More Answers (2)

theta = rand(1024,100);
rho = rand(1024,100);
z = rand(1024,100);
tic; [X,Y,Z] = pol2cart(theta,rho,z); toc
Elapsed time is 0.005789 seconds.
I guess I'm confused on what you are trying to do that takes so long.
Also, I am guessing that the meshgrid() function might be handy for you to convert theta and rho vectors into what you need for this.
Antigoni
Antigoni on 9 Sep 2014
Thank you all for your replies. I didn't mention that my source code is in fortran and only the results' post-processing is made in Matlab.
Briefly, my problem is to simulate the wave propagation in a plate on the x-y plane. For that reason, I solve my equations for various values of x and at different angles. If I use 1024 values of x (which is OK for my resolution) and the same values for angle (since the THETA and RHO must be equally sized), then the Fortran code takes too long. So, now I will try your suggestions in my post-processing.
Though, I have one more question. My input THETA and RHO are vectors of dimensions (1,100) and (1,1024) respectively. In order to use your solutions, I should convert them to matrices, by simply copying and pasting the row as many times as the desired dimensions are reached, right?

5 Comments

Replace my inputs to meshgrid with rho and theta
[rr,thth] = meshgrid(RHO,THETA)
OK, I think I get this (I didn't know this command, I'm sorry). The output matrices X and Y from pol2cart are created in the same manner? Meaning, the rows and columns of X, Y are also copies of a vector?
exactly! Look at a small example:
[xx,yy] = meshgrid(1:3,1:4)
Thank you so much! I will try it in a while and I'll come back later.
Well Sean de Wolski, I tried your solution and it works perfectly! Thanks again for your help!

Sign in to comment.

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!