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
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!