MATLAB Answers

I need an efficient way to color Excel cells based on value using Matlab activeX control

6 views (last 30 days)
Matt on 12 May 2015
I currently process many hundreds of files each with about 24,000 data points. The processed results are then delivered to another team that does not use Matlab so instead an Excel spreadsheet is used. They have an automated tool that reads the sheet so I must output Excel. I have found that I can write the data to Excel very fast using these commands
[nr, nc] = size(array.(fn{i}).minrat');
c1 = get(AS.Cells, 'item', 2, hend + 1);
c2 = get(AS.Cells, 'item', 2 + nr - 1, hend + 1 + nc - 1);
range = get(AS, 'range', c1, c2);
vals = arrayfun(@(x) sprintf('%4.2f',x), array.(fn{i}).minrat, ...
'UniformOutput', 0);
set(range, 'Value', vals');
Applying the colors is much more painful.
color = array.(fn{i}).color';
for j = 1:nr
for k = 1:nc
c1 = get(AS.Cells, 'item', 1 + j, hend + k);
c1.Interior.ColorIndex = color(j, k);
I have used the profiler to show me where all my time is. For a run that took 272 seconds, 266 seconds where that inner loop. Previously the entire Matlab data was written out in the loop and finding the set range value was huge. Is there something I can do similar to that for colors?


Sign in to comment.

Answers (0)