Easy columns merge question
4 ビュー (過去 30 日間)
古いコメントを表示
Hi all, I have an easy merge question.Let's say I have 2 columns that look like this: A = [1 NaN 3 NaN 5 6 ...] and B = [NaN 2 NaN 4 5 6 ...]. Now, I want to merge them so I get C = [1 2 3 4 5 6 ...]. Any ideas? Thanks all!
0 件のコメント
回答 (2 件)
Azzi Abdelmalek
2016 年 6 月 6 日
編集済み: Azzi Abdelmalek
2016 年 6 月 6 日
A = [1 NaN 3 NaN 5 6]
B= [NaN 2 NaN 4 5 6]
C=unique([A B])
C(isnan(C))=[]
3 件のコメント
Azzi Abdelmalek
2016 年 6 月 6 日
A = [1 NaN NaN 4 5 NaN],
B = [1 2 NaN NaN 5 NaN]
i1=isnan(A)
i2=~isnan(B)
C=A
C(i1&i2)=B(i1&i2)
Image Analyst
2016 年 6 月 6 日
Try this:
C = A; % Initialize
% Replace any nan's with B
C(isnan(C)) = B(isnan(C))
3 件のコメント
Image Analyst
2016 年 6 月 7 日
編集済み: Image Analyst
2016 年 6 月 7 日
Then my code works.
It works even if you meant "Yes, the numbers may be different. If so, C take the value of A"
If you wanted B numbers in preference to A, then initialize to B instead of A.
A = [1 NaN NaN 4 5 NaN]
B = [1 2 NaN NaN 5 NaN]
C = A; % Initialize
% Replace any nan's with B
C(isnan(C)) = B(isnan(C))
C =
1 2 NaN 4 5 NaN
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!