作者peter0318 (阿玮)
看板MATLAB
标题Re: [讨论]矩阵转成十进制
时间Wed May 15 21:15:14 2013
你是想做到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
1F:推 peter0318:只要做i跟j两层回圈 剩下的用reshape跟bi2de指令完成 05/15 15:40
2F:→ show109:如果要用我这种方法4层回圈 要怎麽做? 05/15 16:13
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.128.199