Replace values ​​in a matrix

3 Ansichten (letzte 30 Tage)
stelios loizidis
stelios loizidis am 4 Aug. 2021
Hello. I have the following problem.
I have a matrix A with dimensions 1X72. I want in matrix B to have the mean per 24 values. That is, matrix B should be 1X3. Next, I want those values ​​in matrix A above 50 to be replaced by the mean. That is, any value in positions A (1:24) above 50 to be replaced by the mean found in B (1), any value in positions A (25:48) exceeding 50 to be replaced by the mean located in B (2) and any value in positions A (49:72) exceeds 50 to be replaced by the mean in B (3).
Your help is invaluable !!!
  5 Kommentare
stelios loizidis
stelios loizidis am 4 Aug. 2021
% A 1X72
B1=A(1:24);
B1_mean=mean(B1);
B2=A(25:48);
B2_mean=mean(B2);
B3=A(49:72);
B3_mean=mean(B3);
B=[B1_mean,B2_mean,B3_mean];
Rik
Rik am 4 Aug. 2021
Since you seem to be prepared to hard-code the indices: can you think of a way to use my hint to solve your own question?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt J
Matt J am 4 Aug. 2021
A=reshape(A,[],3);
B=mean(A,1);
map=A>50;
A=reshape( A.*(~map)+B.*map , 1,[])
  1 Kommentar
stelios loizidis
stelios loizidis am 4 Aug. 2021
It works. Thank you for your help!!!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by