I am given an array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Thank you very much in advance.
a = [3 4 5 3 64 7 6 34 8 5 4 3];
1 Kommentar
Stephen23
am 6 Dez. 2021
Bearbeitet: Stephen23
am 6 Dez. 2021
Original question by Diego Rosendo Pérez retrieved from Google Cache:
I am given an array with different numbers and I have to compute the same array but with some values changed.
Hi, as you can see I am gven an initial array "a" and I have to create the code to return the same array but with some values changed according to some requirements I have to meet. Now, I have the values and their index but just do not know how to finish the exercise; I think that I need to use a for loop but I just do not know how to code the last line so that I obtain the same array "a" but with some values changed. Thank you very much in advance.
a = [3 4 5 3 64 7 6 34 8 5 4 3];
m = mean(a);
st = std(a);
an = abs(a - m) > st;
ind = find(an);
Antworten (1)
Yongjian Feng
am 30 Nov. 2021
Do you mean:
a = [3 4 5 3 64 7 6 34 8 5 4 3];
m = mean(a);
st = std(a);
an = abs(a - m) > st;
ind = find(an);
a(ind) = an(ind)
1 Kommentar
Yongjian Feng
am 30 Nov. 2021
Bearbeitet: Yongjian Feng
am 30 Nov. 2021
This one?
a = [3 4 5 3 64 7 6 34 8 5 4 3];
m = mean(a);
st = std(a);
an = abs(a - m) > st;
ind = find(an);
a(ind) = 4 % replace all the meet the requirements with 4
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!