Conditional formatting in Excel 2010 from MATLAB

I write an excel sheet using active COM from MATLAB. The sample data is attached in the image.
The columns and rows can vary and are not fixed, i.e. the number of turbines (rows) and number of bins(columns) can vary. I want to condition format for each of the binMean values (B2:Q6). The condition format has to be performed separately for each column.
Following is the conditional formatting required: For each column (i_col), the value of binMean should lie between 9th percentile and 91st percentile. If not, then the color of that cell should be RED! Following is the general matlab code that I wrote to determine these outliers (9th and 91st percentile)
if (binMean(i_turbine,i_col) >= prctile(binMean(:,i_col),9)) && ...
(binMean(i_turbine,i_col) <= prctile(binMean(:,i_col),91))|| ...
isnan(binMean(i_turbine,i_col))
I need help to write the code using active server to condition format from MATLAB.

 채택된 답변

Gaurav Shukla
Gaurav Shukla 2014년 10월 29일

1 개 추천

Excel = actxserver('excel.application');
WB = Excel.Workbooks.Open(File_Path,0,false);
for j=1:length(Result_Frm_Scope)
for i = 1:length(Result_Frm_Scope)
rng = strcat(Starting_Cell,num2str(i+1));
if(Condition_For_Formating )
WB.Worksheets.Item(1).Range(rng).Font.ColorIndex = 4;
% WB.Worksheets.Item(1).Range(rng).Value = 'Pass';
else
WB.Worksheets.Item(1).Range(rng).Font.ColorIndex = 3;
% WB.Worksheets.Item(1).Range(rng).Value = 'Fail';
end
end
end
Just Update the Condition For Formating. It works fine for me.

댓글 수: 2

Ashish
Ashish 2014년 10월 29일
Thanks Gaurav!
Note that you should not use either of i or j for the loop variables, as these are both names of the inbuilt imaginary unit . This is poor coding practice in MATLAB.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

질문:

2014년 10월 29일

댓글:

2015년 1월 4일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by