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.
2 Comments
Direct link to this comment
https://la.mathworks.com/matlabcentral/answers/380874-comparing-elements-of-rows-in-cell-and-columns-in-array-and-plot-results-as-2d-mash-grid#comment_532044
Direct link to this comment
https://la.mathworks.com/matlabcentral/answers/380874-comparing-elements-of-rows-in-cell-and-columns-in-array-and-plot-results-as-2d-mash-grid#comment_532044
Direct link to this comment
https://la.mathworks.com/matlabcentral/answers/380874-comparing-elements-of-rows-in-cell-and-columns-in-array-and-plot-results-as-2d-mash-grid#comment_532048
Direct link to this comment
https://la.mathworks.com/matlabcentral/answers/380874-comparing-elements-of-rows-in-cell-and-columns-in-array-and-plot-results-as-2d-mash-grid#comment_532048
Sign in to comment.