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
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!