MATLAB Answers

0

how to compare an array to a table

Asked by Omar Almahallawy on 1 May 2019
Latest activity Edited by Guillaume
on 2 May 2019
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

Guillaume
on 1 May 2019
they are not stored yet
Surely, these values come from something or somewhere. You don't just make then up as you go along.
It's difficult to answer your question if we don't have a starting point.
this is an engineering question. these tables are handed out to every engineer, i can not figure them out by myself.
i have the array A calculated and stored.
10.3000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 10.3000
10.3000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 9.5000
10.3000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 9.5000
10.3000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 9.5000
9.5000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 9.5000
9.5000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 9.5000
9.5000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 9.5000
9.5000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 9.5000
8.7000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 9.5000
9.5000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 9.5000
8.7000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 9.5000
8.7000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 9.5000
8.7000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 9.5000
8.7000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 9.5000
8.7000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 9.5000
7.9000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 9.5000
7.9000 9.5000 8.7000 8.7000 8.7000 9.5000 9.5000 9.5000 9.5000
now it's a much bigger array than that.
i have an external table a hard copy for each column of this array(A)
i gave an example up above to illastrate a huge question in a massive project.
thank you
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.

Sign in to comment.

Tags

1 Answer

Answer by Guillaume
on 2 May 2019
Edited by 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

Sign in to comment.