26 views (last 30 days)

Show older comments

I have four array in total that are 900x1 each (R1,R2,T1,T2) I am having trouble taking two arrays (T1 and T2) and converting them to have equal spacing. I would like the 2 plots thetas to be changing by the same delta_theta.

is it possible to use meshgrid or interpolation or something else with points that in a polar coodinate system that preserves the same curves? R is not in ascending or descending order but theta is, if so How can I create these equally spaced arrays that produce accurate plots.

Initially, I created equally spaced theta points then try to create new R_data by using interp1 but wasn't able to do this because the R data needed to be in ascending order which messes up the plot.

data=[rr_sort tt_sort tt_spaced rr2_sort tt2_sort]

Code used

rr_new=zeros(900,1);

rr_new(1)=rr_sort(1);

for i=2:900

rr_new(i)=interp1(tt_sort,rr_sort,tt_spaced(i));

end

Chad Greene
on 30 Mar 2021

Ah, it looks like tt_sort and tt2_sort are in fact sorted, but they contain some duplicate values. The easiest way to work around this is to simply ignore the values of rr_sort that correspond to the duplicate entries of tt_sort. This discards the extra datapoints, so depending on your application you may wish to do something else clever (like average all the duplicate value points), but this will get you going:

tt_sort = Data(:,2);

rr_sort = Data(:,1);

tt2_sort = Data(:,5);

rr2_sort = Data(:,4);

tt_spaced = Data(:,3);

ind = diff(tt_sort)>0; % indices where dtheta is nonzero

rr_spaced = interp1(tt_sort(ind),rr_sort(ind),tt_spaced);

polarplot(tt_sort,rr_sort,'o')

hold on

polarplot(tt_spaced,rr_spaced,'x')

ind = diff(tt2_sort)>0; % indices where dtheta is nonzero

rr2_spaced = interp1(tt2_sort(ind),rr2_sort(ind),tt_spaced);

figure

polarplot(tt2_sort,rr2_sort,'o')

hold on

polarplot(tt_spaced,rr2_spaced,'x')

Now one thing I noticed with the first set (tt_sort and rr_sort): I wonder if you want to wrap the phase to the range 0 to 2*pi before interpolating, because the method above interpolates over a large gap in the middle, while it looks like the curve wants to be continuous from +pi to -pi. To see what I mean, try plotting in cartesian coordinates like this:

plot(tt_sort,rr_sort,'o')

hold on

plot(tt_spaced,rr_spaced,'x')

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

Start Hunting!