[問題]矩陣存值問題已回收

看板MATLAB作者 (亂槍打鳥)時間17年前 (2008/12/20 20:30), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
維度640*480 rgb2hsv以後 每個pixel都存在著 [h值 s值 v值] h s v 皆介於0~1 現在要把h 歸類成18等分 s歸類 3等分 v歸類3等分 所以18*3*3 會有162組合 分類方法就是 如果h值 >=0 && <= 1/18 就表示h的第一區間 s跟v如果在第二區間 就變成 (1,2,2) 加個1做紀錄 請問要怎樣作法能夠用 18*3*3的 3d array 紀錄 之後做長條圖存起來 目前小弟的code如下 imgH=zeros(480,640); imgS=zeros(480,640); imgV=zeros(480,640); HSV=zeros(18,3,3); tic; for pp = 1:1 imgb = im2double(imread(['B',num2str(pp),'.jpg'])); imgb=rgb2hsv(imgb); for x=1:480 for y=1:640 h1=0:1/18:1; s1=0:1/3:1; v1=0:1/3:1; for h=1:18 for s=1:3 for v=1:3 hcount=0; scount=0; vcount=0; if imgb(x,y,1)>=h1(h) && imgb(x,y,1)<=h1(h)+(1/18) hcount = hcount+h; end if imgb(x,y,2)>=s1(s) && imgb(x,y,2)<=s1(s)+(1/3) scount = scount+s; end if imgb(x,y,3)>=v1(v) && imgb(x,y,3)<=v1(v)+(1/3) vcount = vcount+v; end HSV(hcount,scount,vcount)=HSV(hcount,scount,vcount)+1; end end end end end end HSV(hcount,scount,vcount)=HSV(hcount,scount,vcount)+1跑到這邊就錯誤了 錯誤訊息是??? Attempted to access HSV(1,1,0); index must be a positive integer or logical. 請問這該怎麼修改 另外想問 if的條件 能夠一次寫嗎 在c裡面 只要只用逗號隔開就可以了 matlab怎麼不能? for也是不能很多變數一個迴圈嗎? ※ 編輯: ADYY7703 來自: 218.168.54.235 (12/21 02:38)

12/21 04:30, , 1F
matlab的索引值是從1開始而不是0
12/21 04:30, 1F
文章代碼(AID): #19JELeQt (MATLAB)
文章代碼(AID): #19JELeQt (MATLAB)