Question

I have a .txt file with cylindrical coordinates, theta, x (would be rho in matlab) and z, all in numbers. I am trying to convert them into cartesian coordinates and then plot them (mesh or surf). I imported the txt file and i have now 3 variables theta,x,z. I used the command [x,y,z] = pol2cart (theta, x, z) but the result is a one column only.

Where I am wrong?

The datas are in columns separated by a blank space:

10.2837 -99.975 36.8826
10.2837 -99.963 36.8826
10.2837 -99.95  36.8826
10.2837 -99.938 36.8826
Was it helpful?

Solution

How can you get a "one column only" output when you specify three output variables. Do you get an error message?

Have you managed to get your data into a matrix? (As a Matlab variable, not a text-file with spaces?) If so, try:

data_mat = [10.2837 -99.975 36.8826
            10.2837 -99.963 36.8826
            10.2837 -99.95  36.8826
            10.2837 -99.938 36.8826];

%% Assuming this order is correct:
theta = data_mat(:,1);
rho = data_mat(:,2);
zz = data_mat(:,3);

[x, y, z] = pol2cart(theta, rho, zz);

Also, remember to transform your angles into radians.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top