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

1 次查看(过去 30 天)
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 个评论
Bob Thompson
Bob Thompson 2018-2-5
What do the coordinates of the instruments matter? Perhaps I am just not understanding what you are trying to plot.
djr
djr 2018-2-5
编辑:djr 2018-2-5
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?

请先登录,再进行评论。

采纳的回答

Bob Thompson
Bob Thompson 2018-2-5
编辑:Bob Thompson 2018-2-5
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 个评论
djr
djr 2018-2-5
Thanks a lot. Your first suggestion for Task 1 works perfectly and it's so simple. :)
For Task 2 I used the scatteredInterpolant function.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by