user2037922
user2037922

Reputation: 33

Matlab vector with on indices values and inbetween zero's

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

Upvotes: 0

Views: 60

Answers (1)

Dennis Jaheruddin
Dennis Jaheruddin

Reputation: 21563

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

Upvotes: 4

Related Questions