Combine two matrices (100 x 1), then find data corresponding to specific rows?

1 回表示 (過去 30 日間)
Paul
Paul 2013 年 10 月 8 日
コメント済み: Paul 2013 年 10 月 8 日
So I have two matrices, each one (100 x 1).
They are equal in regards to their columns and rows, so I'm assuming that saves some headaches. I need to combine them so I can look up requirements in let's say column A, so I can get the corresponding value from column B.
How would I go about combining the two so I can look up values in one to get the corresponding information from the other column in the same row? I want the final matrix two be 100 x 2 , one column being matrix A values, and the second column being matrix B values. Thank you.

採用された回答

Image Analyst
Image Analyst 2013 年 10 月 8 日
rowsToExtract = (some expression giving a logical vector)
extractedRows = [A(rowsToExtract ), B(rowsToExtract);
For a concrete example:
% Create data
A = randi(9, 100, 1);
B = randi(9, 100, 1);
% Create the selection criteria:
rowsToExtract = A>=8
% Get values from both A and B in a single array
% that meet the criteria.
extractedRows = [A(rowsToExtract ), B(rowsToExtract)]
  1 件のコメント
Paul
Paul 2013 年 10 月 8 日
Thank you once again!
How would I go about extracting data from one column based on the criteria of the other column.
For example, in column A, I have a few NaN values, after setting up my own criteria for this column. Column B has a its own values from randn values.
I now want to calculate the average of column B, but only rows that have a corresponding value in column A. Thus, if any value in column B corresponds to a NaN value in column A, I want to exclude that value from my average.
I'm tinkering around with the find function, but no luck yet.

サインインしてコメントする。

その他の回答 (1 件)

James Tursa
James Tursa 2013 年 10 月 8 日
C = [A B];

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by