how to compare an array to a table
    5 views (last 30 days)
  
       Show older comments
    
i have an array(A)  and i want to cross refrence it to an external table that is not inputed on matlab yet.
A=
   10.3000    9.5000    
   10.3000    9.5000   
    9.5000    9.5000 
 EXTERNAL TABLE 
for the first column of A 
  A                   weight                              
9.5	              247.74
10.3	              268.4
for the second column of A
    A                   weight 
  8.7                 216.11 
  9.5                 235.79 
so that the end result would be 
268.4                235.79 
268.4                235.79 
247.74              235.79 
note that for each column the table changes 
7 Comments
  dpb
      
      
 on 1 May 2019
				
      Edited: dpb
      
      
 on 1 May 2019
  
			These numbers look suspicously familiar from the earlier Q? Answers/459589-how-to-compare-two-arrays but we're still at a loss as to what you expect to do with hardcopy data in Matlab.
Unless you can scan it with OCR software or the like, it's essentially unreachable and may as well not even exist.
Perhaps if you actually told us what the particular tables are and the problem you're actually trying to solve one could visualize more clearly and thereby have a possible solution.
Answers (1)
  Guillaume
      
      
 on 2 May 2019
        
      Edited: Guillaume
      
      
 on 2 May 2019
  
      "well that's also a problem i'm facing hoping to find help"
It's difficult for us to help you when you're being very evasive about the source of the data. Matlab is not going to read it from your mind, so it will have to come from somewhere. It can be read from excel file(s), downloaded from the web, painstakingly entered manually, but you're not telling us.
So, as it is, I'm just answering your original question and making up the data:
%demo data
A = [10.3  9.5
     10.3  9.5
     9.5   9.5]
tables = {table([9.5; 10.3], [247.74; 268.4], 'VariableNames', {'A', 'weight'}), ...
          table([8.7; 9.5], [216.11; 235.79], 'VariableNames', {'A', 'weight'})}
assert(numel(tables) == size(A, 2), 'Number of tables does not match number of columns of A');
result = zeros(size(A));
for column = 1:size(A, 2)
   [found, where] = ismember(A(:, column), tables{column}.A);
   assert(all(found), 'Some elements of column %d of A not found is corresponding table', column);
   result(:, column) = tables{column}.weight(where);
end
0 Comments
See Also
Categories
				Find more on Matrix Indexing in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
