我正在尝试找到一种方法使两个列表的长度相同。如何向一个列表添加零,使其与第一个列表具有相同的长度?
即列表1=[ 1 2 3 4 5];列表2=[ 1 2 3]
最佳答案
有很多方法可以做到这一点。其中之一是
list3 = zeros(size(list1)); %# create an array of the same shape as list1
list3(1:numel(list2)) = list2(:); %# fill in the elements defined in list2
另一种方法是
list3 = [list2, zeros(1,length(list1)-length(list2))];
这两种方式都假设 list2
比 list1
短。
关于list - 将零添加到列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5696986/