Changing values in vector
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mr.Chandler
am 16 Nov. 2020
Kommentiert: Mr.Chandler
am 16 Nov. 2020
Hello I have 1000 datas created by "randn" (A=randn(1,1000)). I want to change every value(n) which is not suitable for 1 < abs(A(n)) < 10. Also, new values should have been created by randn again. And it should provides the 1 < abs(A(n)) < 10 condition. So, I think have to create for loop for changing values until they provide the condition. How can I do that?
0 Kommentare
Akzeptierte Antwort
Setsuna Yuuki.
am 16 Nov. 2020
Bearbeitet: Setsuna Yuuki.
am 16 Nov. 2020
You can try this code
a = abs(randn(1,1000))
cont = 1;
while cont < length(a)+1
if(a(cont) < 1 || a(cont) > 10)
a(cont) = randn(1);
cont = 0;
end
cont = cont+1;
end
3 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical 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!