From: Matthew on 9 Aug 2010 21:41 I've got some (r,t,z) triplets (derived from cart2pol) that are in arrays. If you look at (r,t) in polar space, say via plot(r,t), they are in a regular grid (to within roundoff error). However, they are not ordered in a regular way, so I can't do something like reshape. Since values are repeated, I also can't use meshgrid to come up with a nice plaid mesh. (The goal in the end is to integrate in r,t space.) I am also aware of griddata (nice tutorial at http://www.mathworks.com/support/tech-notes/1200/1212.html), but it doesn't do exactly what I want to do either...I'd like to avoid interpolating. (Also true for my end goal, integration.) So my question is if anyone knows of any existing tools for this problem, i.e. tools that can take arrays of unordered coordinate pairs and convert them to plaid matrices, and/or have smart suggestions on how to approach this problem? I have no doubt I could code up a solution, but it seems like there has to be an existing tool out there.
From: Matthew on 10 Aug 2010 00:33 Here's my solution...not sure if it's the most elegant or not. I also recognize that I'm coding for a rather unusual situation. Assume you have arrays r, t, and z, where r and t encompass all the points on a typical mesh grid but are in no particular order. [rs,I]=sort(r); % Sort r [ts,J]=sort(t(I)); % Sort the sorted version of t rs=rs(J); % Rearrange rs such that it matches w/ ts zs=z(I(J)); % Rearrange z as well nunique=length(unique(r)); % Number of unique values reshapesz=[nunique,length(r)/nunique]; % Matrix size for grid R=reshape(rs,reshapesz)'; T=reshape(ts,reshapesz)'; Z=reshape(zs,reshapesz)'; The final data R, T, Z is now in the typical "plaid" format, such that it can be used with surf, etc., i.e. surf(R,T,Z).
|
Pages: 1 Prev: different results between sessions Next: What is the program of excel solver in MatlaB? |