2 differenct size arrays, I want to make the shorter array the same size as the longer by adding Zeros between the indices or the missing numbers and make them the same length
古いコメントを表示
A=[1:10,1:10]'
B=[2 4 6 8 ; 3 3 3 3]'
The output I am trying to aim for is a matrix same size as A but column 2 has the values of B(:,2) see below
Output=[1:10 ; 0 3 0 3 0 3 0 3 0 0]'
I have tried various loops but I get indicies not same used vertcat to add to B the missing values this does not work either, tried all sorts for eg
for ii= 1:10
if ii~=B(ii,1)
B(ii,1)=vertcat(ii,B(:,1));
B(ii,2)=vertcat(0,B(:,2));
else
B(ii,1)=B(ii,1);
B(ii,2)=B(ii,2);
end
end
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!