Matlab绘制一个excel单元格 [英] Matlab paint an excel cell

查看:126
本文介绍了Matlab绘制一个excel单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我在matlab中通过rgb画一个excel单元格吗?
我想要第十个单元格将由rgb绘制。

  values {1}(1,:) = {'1','2' '3','4','5','6','7','8','9','10' 
headers = {'A','B','C','D','E','F','G','H','I','J'};
xlswrite('example.xls',[headers; values {1}]);

谢谢你很多:]

  values = {'1','2','3','4','5','6','7','8','9','10' 
headers = {'A','B','C','D','E','F','G','H','I','J'};
rgb = [255 0 0]; %#如果你有0到1的值乘以255和round
clr = rgb * [1 256 256 ^ 2]'; %'#转换为长数字Excel了解

e = actxserver('Excel.Application'); %#打开ActiveX服务器
filename = fullfile(pwd,'example.xls'); %#full path required
如果存在(filename,'file')
ewb = e.Workbooks.Open(filename); %#打开文件
else
错误('文件不存在')%#或创建一个新文件
end
esh = ewb.ActiveSheet;
for c = 1:numel(values)
esh.Range(strcat(headers {c},values {c}))。Interior.Color = clr;
end
ewb.Save
ewb.Close(false)
e.Quit

您还可以使用十六进制值指定RGB颜色,并使用 hex2dec 。在这种情况下,订单应该相反,如 0000FF 为红色。


can someone help me please in painting an excel cell through rgb in matlab? I want that the 10th cell will painted by rgb.

values{1}(1,:) = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '10'};
headers = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
xlswrite('example.xls', [headers; values{1}]);

thank you a lot :]

解决方案

You can color cells in an existing file with a procedure like this:

values = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '10'};
headers = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
rgb = [255 0 0]; %# if you have 0 to 1 values multiply by 255 and round
clr = rgb * [1 256 256^2]'; %'# convert to long number Excel understands

e = actxserver ('Excel.Application'); %# open Activex server
filename = fullfile(pwd,'example.xls'); %# full path required
if exist(filename,'file')
    ewb = e.Workbooks.Open(filename); %# open the file
else
    error('File does not exist.') %# or create a new file
end
esh = ewb.ActiveSheet;
for c = 1:numel(values)
    esh.Range(strcat(headers{c},values{c})).Interior.Color = clr;
end
ewb.Save
ewb.Close(false)
e.Quit

You can also specified RGB color with hex values and use hex2dec. In this case the order should be opposite, like 0000FF for red.

这篇关于Matlab绘制一个excel单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆