how to compare an array to a table
이전 댓글 표시
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
Guillaume
2019년 5월 1일
So, how will the tables be imported and stored in matlab? One thing for sure, do not load them as individual variables.
Omar Almahallawy
2019년 5월 1일
Guillaume
2019년 5월 1일
How are the tables stored at the moment? How do you know that a particular table matches a given column of A?
Omar Almahallawy
2019년 5월 1일
편집: Omar Almahallawy
2019년 5월 1일
Guillaume
2019년 5월 1일
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.
Omar Almahallawy
2019년 5월 1일
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.
답변 (1개)
"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
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!