Create a vector that gives the information about the locations of each element

I have the vector A: A=[1 3 7], and I want to create another array, say B, that contains the locations of the elements of A. That is, B=[1 0 1 0 0 0 1] Thanks

1 Kommentar

A=[1 3 7];
v=zeros(1,max(A));
% for i=1:length(A)
v(A(:))=1
% end

Antworten (1)

KSSV
KSSV am 29 Dez. 2016
Bearbeitet: KSSV am 29 Dez. 2016
A=[1 3 7] ;
B = zeros(1,max(A)) ;
B(A) = 1
Or Straight away
B(A) = 1

Diese Frage ist geschlossen.

Gefragt:

am 29 Dez. 2016

Geschlossen:

am 20 Aug. 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by