Re: [討論]矩陣轉成十進制

看板MATLAB作者 (阿瑋)時間12年前 (2013/05/15 21:15), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
你是想做到C code上嗎 不然太多for很阿雜 bitmap_pixel=[0 0 0 0; 0 0 0 1; 0 0 1 1; 1 1 0 0] pattern = [8 4; 2 1] sum = 0; for i = 1:2:4 for j = 1:2:4 temp = bitmap_pixel(i:(i+2)-1,j:(j+2)-1); for s = 1:2 for t = 1:2 sum = sum+temp(s,t)*pattern(s,t); end end Dec=sum sum=0; end end ※ 引述《show109 (yu)》之銘言: 我有一個4*4 0和1組成 矩陣 然後我在把他切成2*2 這樣就有4個位置為一組 轉成十進制 0 0 0 0 0 1 0 0 0 1 0 0 1 1 轉成十進制 1 1 0 0 3 12 也就是切成不重疊2*2 區塊 然後轉成十進制 我程式寫完跑出來都錯誤 附上我寫得程式 %把4*4區塊切成2*2 for i = 1:2:x for j = 1:2:y for s = i:i+(2-1) for t = j:j+(2-1) ten_bitmap_pixel(i,j) = bitmap_pixel(s,t)*8+bitmap_pixel(s,t+1)*4+bitmap_pixel(s+1,t)*2+bitmap_pixel(s+1,t+1)*1; end end end end ? Attempted to access bitmap_pixel(1,513); index out of bounds because size(bitmap_pixel)=[512,512]. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.130.12.48

05/15 15:40,
只要做i跟j兩層迴圈 剩下的用reshape跟bi2de指令完成
05/15 15:40

05/15 16:13,
如果要用我這種方法4層迴圈 要怎麼做?
05/15 16:13
-- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.128.199
文章代碼(AID): #1Haufcuq (MATLAB)
文章代碼(AID): #1Haufcuq (MATLAB)