How to plot a polar plot from a matrix or excel file ?

I have a matrix A which contains values at different angles & radius. The index of this matrix represents ( angles,radius ) as (i,j) . Now how to plot these values on a polar plot ? I also want to make a contour plot for these values in polar co-ordinate .
Let the matrix be test file ( analytical.csv) attached with this document. It contains 5 columns and 4 rows , colums represent different radius = ( 0 , 0.25, 0.50 , 0.75 , 1 ) and rows represent different angles = ( 0 , pi/2 , pi , 3pi/2 ) respectively.
Thanks

5 Comments

It showing an error,
Attempt to execute SCRIPT plot as a function: /Users/anshumansinha/Desktop/plot.m
Error in polar (line 227) q = plot(xx, yy, 'Parent', cax);
Error in untitled2 (line 40) h = polar(X,Y);
if true
m = input ('M in multiple of 4*2^r ');
n = input ('N in n+1 taking 0 as well , e.g 5 ');
sol= zeros(m,n);
s=0;
for j = 1:n
for i = 1:m
r = 0.03*(j-1)*(1/(n-1)) ;
fi = 2*pi*(i-1)/(m) ;
%disp(r)
%disp(fi)
%disp('r,fi')
for m1 =1:10000
s = s + (2*cos(2*m1*fi)*((r/0.03)^(2*m1))) / ((4*m1*m1 - 1)*(1 +
(2*m1*45)/(20*0.03)));
%disp(s)
end
A(i,j)= (1353/20)*(1/pi - (s/pi) + ((r/0.03)*sin(fi))/(2*(1+
(45/(20*0.03)))));
end
end
%filename = 'analytical1';
%xlswrite(filename,sol)
%[A,txt,raw] = xlsread('analytical1.csv') ;
r = [ 0 , 0.25, 0.50 , 0.75 , 1] ;
th = [ 0 , pi/2 , pi , 3*pi/2 ] ;
[R,T] = meshgrid(r,th) ;
% Create polar data
% Convert to Cartesian
X = R.*cos(T);
Y = R.*sin(T);
h = polar(X,Y);
hold on;
contourf(X,Y,A);
% Hide the POLAR function data and leave annotations
set(h,'Visible','off')
% Turn off axes and set square aspect ratio
axis off
axis image
%disp(sol)
% code
end

Sign in to comment.

Answers (2)

[A,txt,raw] = xlsread('C:\Users\srinivas\Downloads\analytical.csv') ;
r = [ 0 , 0.25, 0.50 , 0.75 , 1] ;
th = [ 0 , pi/2 , pi , 3*pi/2 ] ;
[R,T] = meshgrid(r,th) ;
% Create polar data
% Convert to Cartesian
X = R.*cos(T);
Y = R.*sin(T);
h = polar(X,Y);
hold on;
contourf(X,Y,A);
% Hide the POLAR function data and leave annotations
set(h,'Visible','off')
% Turn off axes and set square aspect ratio
axis off
axis image

5 Comments

It showing an error,
Attempt to execute SCRIPT plot as a function: /Users/anshumansinha/Desktop/plot.m
Error in polar (line 227) q = plot(xx, yy, 'Parent', cax);
Error in untitled2 (line 40) h = polar(X,Y);
In MATLAB, it is possible for the same file name to exist in multiple directories. In some situations the version that is chosen is determined by the data types of the variables involved, but otherwise the version chosen is determined by which directory appears first on the MATLAB path, with the current directory having priority in most cases.
You defined your own plot.m either in the current directory or in a directory that is high up in your MATLAB path. In MATLAB, that means that every time that there is call to plot that is not satisfied according to datatype rules (object methods), that your plot.m should be used to override the Mathworks provided plot .
However, the Mathworks provided plot is a function that expects arguments, whereas your plot.m is a script - the first line of it does not start with the word function or classdef.
You will need to upgrade your plot.m into being a function that can accept most of the arguments that the Mathworks provided plot function can accept.
Out of curiosity: what is your motivation for overriding the Mathworks provided plot function? For example are you working on an experimental Re implementation using DirectX instead of OpenGL?
I am not able to follow the instructions on my computer system, can you please help with the contour plot of this matrix which I am attaching with this comment.
The matrix is 64x8 , where 64 is number of points corresponding to phi angle and 8 is the points corresponding to radius. i.e for radius it's R = [0 1/8 2/8 3/8 4/8 5/8 6/8 7/8] similarly for phi [ 0 2pi/64 4pi/64 ...... 62pi/64 ].
Walter , May you please help me with this !
You have chosen to replace Mathwork's plot.m with your own. Because plot() is called in many places in MATLAB, you will need to upgrade your plot.m to handle all of those cases, which will take a lot of work.
What is it that you are extending plot() to be able to handle that it does not handle already ?
Because a partly-completed plot.m is likely to interfere with your use of MATLAB until you have completely finished your fully-compatible extension or replacement of plot(), we would recommend that you name your plot.m by some other name while you work through the development stages.
... We are not sure what any of this has to do with the task of drawing a contour plot of that matrix. Why not use the regular contour() call to do that instead of developing a complete replacement for plot() ?

Sign in to comment.

Do not call your m-file plot.m. Call it myPlot.m or something like that. Obviously change the name inside the file too.

Categories

Asked:

on 12 Oct 2018

Commented:

on 12 Oct 2018

Community Treasure Hunt

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

Start Hunting!