How to pad NaNs in a matrix having small size to make equivalent with matrix of large size?
40 ビュー (過去 30 日間)
古いコメントを表示
Hi there,
Suppose I have given matrices A= [1 2 3; 4 5 6; 7 8 9] and B=[1 2; 3 4]. Now, I just wanted to pad NaNs in matrix B to make equal size to that of A. Your help will be greatly appreciated.
Thank you in advance.
0 件のコメント
採用された回答
Voss
2022 年 6 月 12 日
A = [1 2 3; 4 5 6; 7 8 9];
B = [1 2; 3 4];
[ma,na] = size(A);
[mb,nb] = size(B);
% one way:
B_new = [B NaN(mb,na-nb); NaN(ma-mb,na)]
% another way:
B_new = NaN(ma,na);
B_new(1:mb,1:nb) = B
その他の回答 (1 件)
Jan
2022 年 6 月 12 日
A = [1 2 3; 4 5 6; 7 8 9];
B = [1 2; 3 4];
C = padarray(B, max(0, size(A) - size(B)), NaN, 'post')
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!