Comparing elements of rows (in cell) and columns (in array) and plot results as 2D mash/grid

1 view (last 30 days)
Hello,
I have a cell A (attached) where the first column is the instrument number and the other two columns are x and y coordinates of each instrument. At the same time, I have an array B (attached) which contains time series of measurements for each instrument, and the first row is the instrument number. Note that I have more columns in B than rows in A (i.e., more instruments in B than in A).
  1. I would like to extract only the columns in B that correspond to the instrument numbers in A.
  2. The results should be presented as the time averages on 2D grid. I have coordinates of each instrument in A.
Please can you help me with this? I assume that the task (1) can be obtained using accumarray function, but to be honest I find that function very confusing. Not sure how to use it correctly.
Thank you,
DjR
  2 Comments
Bob Thompson
Bob Thompson on 5 Feb 2018
What do the coordinates of the instruments matter? Perhaps I am just not understanding what you are trying to plot.
djr
djr on 5 Feb 2018
Edited: djr on 5 Feb 2018
They don't for the task (1). However, they do for the task (2) I believe. They represent ( x, y) of each instrument. I graphically portrayed it in Paint and attached. :) Instruments are small circles in the plot.
I mean, how else to interpolate if I don't know the values in certain points?

Sign in to comment.

Accepted Answer

Bob Thompson
Bob Thompson on 5 Feb 2018
Edited: Bob Thompson on 5 Feb 2018
Fair warning, I have not actually looked at the arrays you presented.
Task 1 can be completed in a couple of different ways. If you just want to remove the columns of B which do not have a corresponding instrument in A, then you can do a match check:
check = ismember(B(1,:),A{:,1});
B = B(check == 1,:);
This check looks for values in the first row of B that match with values in the first column of A and then removes all rows of B which do not match. This will technically get rid of your time column in B, so you may want to tweak which columns of B it look at.
If you want extract the columns of B and put them into A then I would suggest using find.
for I = 1:length(A(:,1));
[row,col] = find(A{I,1},B(1,:));
A{I,4} = B(2:length(B),col);
end
This bit may take some tweaking as well, as I originally used it to look for string headers, but it basically looks for columns in B which have matching instrument numbers as each instrument number in A, and then adds the rest of the B column as an array in A. This is a bit more computationally intensive method, but does move all the data into A (except time).
For Task 2, I'm still not entirely sure what you're trying to plot, but that's probably just my inability to visualize things well. What I understand is that you're looking to plot each instrument at an x,y coordinate, and then plot certain time average values for each of those instruments. If this is the case then I would suggest just a standard mesh or surface 3D plot. These both follow a general surf(x,y,z) format, so you could plot them as:
surf(A{:,2},A{:,3},mean(A{:,4}))
This particular code might end up averaging all of the arrays in the fourth column of A, but the mean function will give you some form of average.
Let me know if there is something you don't understand, I would be happy to try something else.
  1 Comment
djr
djr on 5 Feb 2018
Thanks a lot. Your first suggestion for Task 1 works perfectly and it's so simple. :)
For Task 2 I used the scatteredInterpolant function.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!