How can I access a submatrix as an array inline?
조회 수: 4 (최근 30일)
이전 댓글 표시
I am trying to avoid adding extra/unneeded variables and code to my matlab scripts.
I have noticed that when I access a submatrix inline, I will get a different result than if I make a separate variable of the submatrix beforehand and use the colon operator in my reference.
For Example: -Let A be a 576x720x3 matrix. B=A(50:100,50:100,1); [a1,b1]=histc(A(50:100,50:100,1),0:255); [a2,b2]=histc(B(:),0:255);
This results in a case where a1 != a2 and b1 != b2. They have the same basic values, but a1 & b1 appear to be groups of histograms of smaller data sets (51x51 matrix input), while a2 & b2 are a single histogram of the full submatrix dataset (51x51=2601 elements).
Does anyone know how to get the [a2,b2] result without using the extra variable B? (i.e. is there a way to use an inline reference to a submatrix of A that returns the data as a single column?)
Thanks, Sean
댓글 수: 0
채택된 답변
Sean de Wolski
2011년 6월 30일
The problem is that B(:) is not the same shape as B which is equal to A(..).
To fix:
A = imread('peppers.png');
B=A(50:100,50:100,1);
[a1,b1]=histc(reshape(A(50:100,50:100,1),[],1),0:255);
[a2,b2]=histc(B(:),0:255);
isequal(a1,a2)
isequal(b1,b2)
reshape A(..) before the call to histc
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!