Creating a new array that contains number of overlap of non-zero values
3 次查看(过去 30 天)
显示 更早的评论
I have 4 equally sized arrays (under ARV.HEMEsubt_otsu), and the 'ARV' structure is attached with this question. I'm trying to create an array of equal size (105 x 107 double) that shows the total of the other arrays have non-zero values (i.e. 0, 1, 2, 3, or all 4). So for instance, at the row 75, column 57 cell location, only mz316 has a non-zero value so the new array would have a 1 in that cell in the new array.
I surmise a for loop that goes through the entire array and then assessing the others' cell values, but does anyone have any thoughts?
Happy to provide additional clarification as needed. Thanks!
0 个评论
采纳的回答
Image Analyst
2021-11-28
编辑:Image Analyst
2021-11-28
Zeros add to zero, so why don't just add up those 4 arrays:
s=load('Arrays_11282021.mat')
s1 = s.ARV.HEMEsubt_otsu
m = s1.mz248 + ...
s1.mz288 + ...
s1.mz316 + ...
s1.mz445
imshow(m, [], 'InitialMagnification', 1600);
axis('on', 'image')
If you don't want the values themselves added, but just add 1 regardless ofthe value in there, just threshold at zero before adding:
s=load('Arrays_11282021.mat')
s1 = s.ARV.HEMEsubt_otsu
m = s1.mz248 > 0 + ...
s1.mz288 > 0 + ...
s1.mz316 > 0 + ...
s1.mz445 > 0
imshow(m, [], 'InitialMagnification', 1600);
axis('on', 'image')
2 个评论
Image Analyst
2021-11-29
Try this:
s = load('Arrays_11282021.mat')
s1 = s.ARV.HEMEsubt_otsu
m = uint8(s1.mz248 > 0) + ...
uint8(s1.mz288 > 0) + ...
uint8(s1.mz316 > 0) + ...
uint8(s1.mz445 > 0);
imshow(m, [], 'InitialMagnification', 1600);
axis('on', 'image')
impixelinfo; % Show (x,y) and value
colormap(lines(5))
colorbar
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/816514/image.png)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!