0
votes

In Matlab I have given a list of indices (e.g. a = [2 7]) and values (e.g. b = [123 642]. I need a function f which returns a vector (c) with the values at the given the indices and zeros inbetween.

so: c = [0 123 0 0 0 0 642]

How can I perform this task?

regards,

Vcent

1

1 Answers

4
votes

You can use linear indexing:

c = zeros(1,max(a)); %Not required if c does not exist, but I would recommend it
c(a) = b