Reputation: 33
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
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