您当前的位置: 首页 >  matlab

slandarer

暂无认证

  • 1浏览

    0关注

    248博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

matlab RGB颜色转16进制颜色

slandarer 发布时间:2020-03-22 21:10:05 ,浏览量:1

程序:

function string=ten2sixteen(num)
%the num should be a 1x3 Integer mat limited in [0 255]
exchange_list={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
string='#';
for i=1:3
    temp_num=num(i);
    string(1+i*2-1)=exchange_list{(temp_num-mod(temp_num,16))/16+1};
    string(1+i*2)=exchange_list{mod(temp_num,16)+1};
end
end

效果: 在这里插入图片描述 转换回去程序:

function num=sixteen2ten(string)
    exchange_list='0123456789ABCDEF#';
    num=zeros(1,3);
    for i=1:3
        tempCoe1=find(exchange_list==string(i*2))-1;
        tempCoe2=find(exchange_list==string(i*2+1))-1;
        num(i)=16*tempCoe1+tempCoe2;
    end
end

效果: 在这里插入图片描述

关注
打赏
1664692598
查看更多评论
立即登录/注册

微信扫码登录

0.0388s