Calling specific cells and averaging

조회 수: 1 (최근 30일)
Edward Lannon
Edward Lannon 2020년 11월 16일
댓글: Edward Lannon 2020년 11월 16일
Hello,
I have a 3000X3000 matrix. I also have a list of coordinates that I would like to use to indicate which values to select and average all the selected values. I can't seem to do it. I attached an example of a list.
Thank you for your time.
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2020년 11월 16일
Edward - please explain how the list of coordinates relates to the 3000x3000 matrix.
Edward Lannon
Edward Lannon 2020년 11월 16일
Sure thing. I would like to average values located in cells within a 3000X3000 matrix. These specific cells within the 3000X3000 do not follow any real pattern, so I constructed a list of coordinates that notes the location of each cell. So, basicaly the list attached has the locations coordinates (rows, colums) for 365 cells within the larged 3000X3000 matrix that I would like to aggragate and compute an average for.
Thanks for asking

댓글을 달려면 로그인하십시오.

채택된 답변

Hrishikesh Borate
Hrishikesh Borate 2020년 11월 16일
Hi,
I understand that you want to calculate average of elements present at indices stored in the file “VisualVisualTest.mat”. This can be done using following code:-
visualTest = load('VisualVisualTest.mat');
a = magic(3000); %3000x3000 matrix
visualCordsall = visualTest.VisualVisualCordsall;
indicesMatrix = transpose(reshape(cell2mat(visualCordsall),2,[]));
sz = [3000, 3000];
ind = sub2ind(sz, indicesMatrix(:,1), indicesMatrix(:,2));
avgValue = mean(a(ind));
Where, avgValue stores the average value.
For more information, refer to sub2ind, cell2mat.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by