Subscript indices must either be real positive integers or logicals.while using indexing
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
want2know
am 17 Feb. 2014
Kommentiert: want2know
am 17 Feb. 2014
Hi all,
After performing some processing, now the variable 'a' contains [2 5 9].
Let say i have another variable 'b', variable 'b' is pre-initialized to be zero depending on a length of input, let say 10. b = [0 0 0 0 0 0 0 0 0 0];
What I want is, the elements that are stated in variable 'a' should be set ONE in variable 'b'. b= [0 1 0 0 1 0 0 0 1 0]
I did make sure variable 'a' contains only positive integers.
have added this line "a=round(a); b(a)=1;"
'a' can only be positive integers, I confirm and have checked.
I still I got the same error... Appreciate any idea, thanks
0 Kommentare
Akzeptierte Antwort
Mischa Kim
am 17 Feb. 2014
Use clear all and then copy-paste-execute
a = [2 5 9];
b = [0 0 0 0 0 0 0 0 0 0];
b(a) = 1
Does that do the trick?
4 Kommentare
Weitere Antworten (1)
Jos (10584)
am 17 Feb. 2014
Are you sure they are positive and larger than zero ? … I am pretty sure they are not!
remove the semi-colon to see
a = round(a)
b(a) = 1
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!