Change colour of cells of an excel worksheet imported into matlab
조회 수: 41 (최근 30일)
이전 댓글 표시
Hi Guys,
I have an excel spreadsheet that contains a table of results of correlations between variables. I would like to read this document into matlab, then use a code that will loop through the worksheet and highlight every cell that is <0.05 in the colour green (to show a significant correlation), what code would I use to do this please?
Thanks
댓글 수: 2
Sindar
2020년 3월 9일
Why do you want to use Matlab for this?
(In Excel, you can use conditional formatting to do the same thing in one step)
Walter Roberson
2020년 3월 12일
https://www.mathworks.com/matlabcentral/answers/509463-coloring-variable-cells-in-excel is pretty much the same.
답변 (1개)
Monisha Nalluru
2020년 3월 12일
I have attached the excel file for the reference work.
The code below is used to color a cell in third column with values greater than 5.
m=xlsread("testing.xlsx");
% Connect to Excel
Excel = actxserver('Excel.application');
% Get Workbook object
WB = Excel.Workbooks.Open(fullfile(pwd, 'testing.xlsx'),0,false);
for i=1:numel(m(:,3))
if m(i,3)>5
cell="C"+num2str(i);
% Set the color of required cell of Sheet 1 to GREEN
%color Index for GREEN is 4 in excel
WB.Worksheets.Item(1).Range(cell).Interior.ColorIndex = 4;
end
end
% Save Workbook
WB.Save();
% Close Workbook
WB.Close();
% Quit Excel
Excel.Quit();
Refer the following link:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!