Cartesian to polar coordinates on matlab
时间:04-04
整理:3721RD
点击:
Hi everyone,
I understand how the equations for the function works.
r = sqrt(x^2+y^2)
theta = atan(x/y)
But am a bit weak in programming so don't know how many for loops I need to use to covert a .txt file 1601 X 604 in Cartesian to polar format. If someone has constructed an algorithm that converts arrays of data from cartesian to polar, or has a .m algorithm created by any generous smart guy ready to share, please let me know or share the algorithm with me.
Many Thanks
Henry797
The the contents are copied to the variable raw, which is a 1001x488 double. But there are no headers in the txt file to figure out what it represents. What is the actual format of the data?
Then you just have to print polarout to a new text file.
I understand how the equations for the function works.
r = sqrt(x^2+y^2)
theta = atan(x/y)
But am a bit weak in programming so don't know how many for loops I need to use to covert a .txt file 1601 X 604 in Cartesian to polar format. If someone has constructed an algorithm that converts arrays of data from cartesian to polar, or has a .m algorithm created by any generous smart guy ready to share, please let me know or share the algorithm with me.
Many Thanks
Henry797
Depends on how the txt file is formatted. Can you post an example?
Please download the file from the below link.
Let me know if you can't access the file
[Moderator's attachment expired. Link to file is in following post.]
1.7z
I've attached the zip file. Hopefully you'll be able to extract it!
If I use:
Code:
raw=load('1.txt');
Hi if you import it into matlab, you'll be able to get the columnar form where the odd columns represent real part of transmission in linear scale and the even columns imaginary
If you cannot format it to columnar form, please let me know.
I want the columns to be converted to rho and theta (magnitude and phase)
Regards
Henry797
Try this:
Code:
raw=load('1.txt'); R=raw(:,1:2:end); I=raw(:,2:2:end); M=abs(R+1i*I); phi=angle(R+1i*I); polarout=zeros(size(raw)); polarout(:,1:2:end)=M; polarout(:,2:2:end)=phi;