gpt4 book ai didi

list - 将零添加到列表中

转载 作者:行者123 更新时间:2023-12-01 12:45:56 24 4
gpt4 key购买 nike

我正在尝试找到一种方法使两个列表的长度相同。如何向一个列表添加零,使其与第一个列表具有相同的长度?

即列表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))];

这两种方式都假设 list2list1 短。

关于list - 将零添加到列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5696986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com