Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在Matlab中,我给出了一个索引列表(例如a = [2 7])和值(例如b = [123 642]。我需要一个函数f,它返回一个向量(c),其中的值在给定的索引和之间的零。
所以:c = [0 123 0 0 0 0 642]
我该如何执行此任务?
问候,
文森特
您可以使用线性索引:
c = zeros(1,max(a)); %Not required if c does not exist, but I would recommend it c(a) = b