필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

quick syntax question for saving run time

조회 수: 1 (최근 30일)
jenka
jenka 2012년 9월 18일
마감: MATLAB Answer Bot 2021년 8월 20일
I have the following:
m1 = rand(5,5)
m2 = rand(5,5)
m3 = rand(5,5)
m4 = rand(5,5)
m3D = cat(3, m1, m2, m3, m4);
% Find the min and a map of what matrix it occurred in.
[min2DImage matrixWhereItOccurs] = min(m3D, [], 3)
Now I would like to have accumlation array where I update that array by adding one to the 3rd dimension with index referenced from matrixWhereItOccurs
sz = sz(m3D);
accum_arr = zeros(sz(1),sz(2),sz(3)
Let's say matrixWhereItOccurs(2,3)=4, then accumm_arr(2,3,4)=accum_arr(2,3,4)+1; I want to do this for ALL elements now without going into loop as in my work the arrays are huge.Could you please help? Thanks
  댓글 수: 2
per isakson
per isakson 2012년 9월 18일
Please format to save my time :)
jenka
jenka 2012년 9월 18일
sorry.here it is.

답변 (1개)

Honglei Chen
Honglei Chen 2012년 9월 18일
편집: Honglei Chen 2012년 9월 18일
ind = sub2ind(sz,repmat((1:sz(1))',1,sz(2)),repmat(1:sz(2),sz(1),1),...
matrixWhereItOccurs);
accum_arr(ind(:)) = accum_arr(ind(:))+1;

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by