看板 MATLAB 關於我們 聯絡資訊
現在將一張影像做完標記後 想要找出標記影像中像素最多的三個區域 程式如下 [L,n]=bwlabel(imgs,8); count=zeros(1,max(max(L))); for i=1:size(L,1) for j=1:size(L,2) count(L(i,j))=count(L(i,j))+1; end end sf=sortrows(count'); 想請問各位前輩 為何for迴圈中的count(L(i,j))=count(L(i,j))+1會一直跳錯誤 那要如何去修正呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 175.180.77.22
aada:錯誤訊息是? 10/24 08:10
andycho:Attempted to access count(0) 10/24 16:15
andycho:index must be a positive integer or logical 10/24 16:17
andycho:以上兩行便是我Command Window出現的錯誤訊息 10/24 16:18
aada:L(i,j)有為0的嗎y 10/24 17:08
aada:因為count裡面並沒有位置0的數據 10/24 17:09
aada:試試看: count(L(i,j)+1)=count(L(i,j)+1)+1 10/24 17:10
andycho:照您的方法,count內有東西了 10/24 20:57
andycho:但這次出現的錯誤是Attempted那行的count()內為count(22) 10/24 20:59
andycho:怎麼樣處理這個問題會比較好呢?改迴圈size試過但沒辦法 10/24 21:01
andycho:謝謝aada,上述問題已經解決 10/24 23:36
※ 編輯: andycho 來自: 175.180.77.22 (10/24 23:57)
aada:不客氣, 所以現在的問題都解決了? 10/25 07:58