MATLAB Answers

Selecting a block of values in a matrix.

조회 수: 8(최근 30일)
Sam Kanakkanatt
Sam Kanakkanatt 16 Apr 2021 2:43
답변: Matt J 16 Apr 2021 4:13
I am currently working on a problem where were are given a matrix that can vary in size. Then we must select a block (5x5) of that matrix starting from the top left corner and replace all the values with the average of those values. After that this process is repeated for the entirety of the matrix. I believe I can do the code to find the average and replace the values, but I do not know were to start to select the blocks of the matrix. I know that I need to use nested for loops but so far I have not been able to get it.
Thanks in advance :)

답변(1개)

Matt J
Matt J 16 Apr 2021 4:13
Loops are not needed. Using sepblockfun (which you must Download)
yourMatrix=randi(100,10); %example
result=repelem(sepblockfun(yourMatrix,[5,5],'mean'),5,5)
result = 10×10
51.9200 51.9200 51.9200 51.9200 51.9200 51.3200 51.3200 51.3200 51.3200 51.3200 51.9200 51.9200 51.9200 51.9200 51.9200 51.3200 51.3200 51.3200 51.3200 51.3200 51.9200 51.9200 51.9200 51.9200 51.9200 51.3200 51.3200 51.3200 51.3200 51.3200 51.9200 51.9200 51.9200 51.9200 51.9200 51.3200 51.3200 51.3200 51.3200 51.3200 51.9200 51.9200 51.9200 51.9200 51.9200 51.3200 51.3200 51.3200 51.3200 51.3200 51.7600 51.7600 51.7600 51.7600 51.7600 44.8800 44.8800 44.8800 44.8800 44.8800 51.7600 51.7600 51.7600 51.7600 51.7600 44.8800 44.8800 44.8800 44.8800 44.8800 51.7600 51.7600 51.7600 51.7600 51.7600 44.8800 44.8800 44.8800 44.8800 44.8800 51.7600 51.7600 51.7600 51.7600 51.7600 44.8800 44.8800 44.8800 44.8800 44.8800 51.7600 51.7600 51.7600 51.7600 51.7600 44.8800 44.8800 44.8800 44.8800 44.8800

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by