フィルターのクリア

Take elements from a cell variable to other based on a condition

1 回表示 (過去 30 日間)
Maria
Maria 2014 年 8 月 11 日
コメント済み: Maria 2014 年 8 月 11 日
I have a cell type variable A with 8 rows and 500 columns:
code1 year value code1 *code2*
A={ 1037 1999 50,2 1037 110 [] [] 1
1062 1999 50,2 1062 *[]* [] [] 0
1242 1999 58,4 1242 *[]* [] [] 0
1255 1999 56,2 1255 881 [] [] 1}
And a cell type variable B with 21 rows and 10000 columns:
x 1994 1995 1996 1997 1998 1999 2000 2001 ...
B= {1037 110 110 110 110 110 110 873 873
1039 721 721 1242 [] [] [] [] []
1050 495 495 495 495 829 282 282 []
1062 228 228 228 282 282 *282* [] []
1242 86 86 86 86 86 *86* [] []
1249 118 37 37 37 37 37 37 []
1254 7 7 7 7 7 7 157 157
1255 37 37 37 37 37 881 16 16}
code2 is missing in some rows of variable A.
I would like to complete the 5th column of A (code2) by going to the 7th column of B(1999) and if A(:,1) and B(:,1)match ( code1 and 'x' ), place that value in A.
My new A would be:
code1 year value code1 *code2*
ANEW={ 1037 1999 50,2 1037 110 [] [] 1
1062 1999 50,2 1062 *282* [] [] 0
1242 1999 58,4 1242 *86* [] [] 0
1255 1999 56,2 1255 881 [] [] 1}
Can someone help me? Thank you.
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 8 月 11 日
This is not clear
Maria
Maria 2014 年 8 月 11 日
I edited it now,is it more clear?

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

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 8 月 11 日
編集済み: Azzi Abdelmalek 2014 年 8 月 11 日
ic5=find(cellfun(@isempty,A(:,5) ))
for k=ic5'
ib1=find(cell2mat(B(:,1))==A{k,1})
if ~isempty(ib1)
A(k,5)=B(ib1,7)
end
end

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by