Effacer les filtres
Effacer les filtres

How to color excel cell backgrounds with Matlab?

6 vues (au cours des 30 derniers jours)
Snowfall
Snowfall le 17 Fév 2016
Modifié(e) : Snowfall le 18 Fév 2016
I have a matrix which I would like to input in excel and I would like to color every cell which is between certain range. And I know that I can do that by using ActiveX but all the examples I found didn't help me too much.
To found the cells within my range I've written a code like below and I would like to color those cells in MyMatrix which are 1 (ones) in IndexMatrix.
Is there a good way to do this?
MyMatrix=rand(5)
Rows=size(MyMatrix,1);
for i=1:Rows
idx = MyMatrix(i,:) >= 0.2 & MyMatrix(i,:) <= 0.5;
IndexMatrix(i,:)=[idx];
end
IndexMatrix
[filename pathname] = uiputfile({'*.xlsx'});
FileNameString=strcat(pathname, filename); %Same as FullFileName
myfile = filename;
xlswrite(myfile,MyMatrix);

Réponses (1)

Image Analyst
Image Analyst le 17 Fév 2016
Modifié(e) : Image Analyst le 17 Fév 2016
Did you try this:
Excel.Worksheets.Item(1).Range(cellReference).Interior.ColorIndex = cellFillColorIndex;
  1 commentaire
Snowfall
Snowfall le 18 Fév 2016
Modifié(e) : Snowfall le 18 Fév 2016
Thank you for your answer I probably need to show my stupidity more clearly...
I did try what you suggested but my problem is that I don't figure out that what should I write in place of "cellReference" because in all the examples that I have found the "cellReference" should be in excel notation (like A1 or A4;B1 or such). While in my case I would like to understand that how I can apply a matrix (in my case IndexMatrix) in 'cellReference'? Or is that even possible?

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by