フィルターのクリア

If statement in cell arrays

1 回表示 (過去 30 日間)
Bas
Bas 2015 年 9 月 17 日
コメント済み: Bas 2015 年 9 月 17 日
Hi,
I have a matrix A of 1x24 cells. Each cell contains c x 1 values, with c being variable. So A{1} is 2360x1, while A{2} is 2340x1 etc. The values in A define ages of people.
I have a matrix B 45x2, B(:,1) are ages, B(:,2) are corresponding values to the specific age on the same row.
Now I want to check for each value in A, what is the corresponding value from B(:,2). So what I want as output is C with 1x24 cells, with all corresponding values to the specific ages in A.
Can anyone help me with this?

採用された回答

Walter Roberson
Walter Roberson 2015 年 9 月 17 日
for K = 1 : length(A)
[tf, idx] = ismember(A{K}, B(:,1));
t = nan(length(A{K},1);
t(tf) = B(idx(tf),2);
C{K} = t;
end
You did not specify what to do for ages that did not match anything.
  1 件のコメント
Bas
Bas 2015 年 9 月 17 日
Thanks, if the age in A is lower than min(B(:,1)) it should be B(1,2) and if the age in A is higher than max(B(:,1)) it should be B(end,2).

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by