필터 지우기
필터 지우기

How to use arrayfun or cellfun on m x n x o matrix where it performs operation on each m x n matrix

조회 수: 5 (최근 30일)
Hi,
Please let me preface my question by stating my intent. My goal here is for work flow automation and to reduce code, not for execution speed.
I have in this case a standard RGB image which consists of an mxnxo matrix, of which o is size 3. Therefore there are 3 mxn matrices in which each represents intensity values of the respective R,G,and B channels. I wish to use array fun in this case, to return a 3 element cell array that contains the histcounts inside of each cell element for the respective channels in my image.
Another more generic way to think about this is; I want to perform a function on each mxn in my mxnxo matrix. Rather than to index each one R = (:,:,1) G = (:,:,2) B = (:,:,3)....histcounts( R ) histcounts(G) histcounts(B).
The problem I have is the syntax for this in arrayfun or cellfun. e.g. arrayfun(@histcounts,img(:,:,?))
Thanks in advance, Chris

채택된 답변

Matt J
Matt J 2018년 4월 4일
편집: Matt J 2018년 4월 4일
out = arrayfun( @(i) histcounts(img(:,:,i)), 1:3, 'uni',0)
  댓글 수: 3
Matt J
Matt J 2018년 4월 4일
Of course, a simple for-loop would work fine, too
for i=1:3
out{i}=histcounts(img(:,:,i));
end
Chris Knab
Chris Knab 2018년 4월 4일
Of course, in my case I was interested in the syntax you provided as it can be used in many other scenarios I come across. I am often working in lives scripts trying to prototype some analysis and accessing data this way with less code is much cleaner.
Thanks!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by