Conditional formatting in Excel 2010 from MATLAB
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Gaurav Shukla
2014-10-29
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 个评论
Stephen23
2015-1-4
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!