MATLAB: Conditional formatting in Excel 2010 from MATLAB

activexconditional formattingexcel-matlab interfacing

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.

Best Answer

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.