How can I access a submatrix as an array inline?
3 次查看(过去 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!