Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Writing few data in Excel in one sheet

2 vues (au cours des 30 derniers jours)
Ivana
Ivana le 27 Nov 2016
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hello. I have read a few image and RGB values (seperate to one column, without some pixel values, but thats not matter) for about 30 images from one folder. How to put all this data in one sheet, to begin in second row A2 and cetera... Here is my code:
allImages=dir(pwd)
for f=1:size(allImages)
if ~allImages(f).isdir
x2=imread(allImages(f).name);
redChannel = x2(:, :, 1);
greenChannel = x2(:, :, 2);
blueChannel = x2(:, :, 3);
matricaB=[];
A=size(blueChannel)
kolone=A(1)
vrste=A(2)
for i=1:kolone
for j=1:vrste
if redChannel(i,j)~=17 && greenChannel(i,j)~=24 && blueChannel(i,j)~=32
matricaB=[matricaB;redChannel(i,j) greenChannel(i,j) blueChannel(i,j)]
end
end
end
xlswrite('all-files.xlsx', matricaB, f);
end
end
This code put my values in separate sheets from sheet 3, don't know why, but this is not matter. I would like to store RGB values from first picture, 3 columns, from A2-C2, than RGB values from second picture from E2-G2, etc.
How to do that? Thanks!
  1 commentaire
Ivana
Ivana le 27 Nov 2016
Modifié(e) : Walter Roberson le 27 Nov 2016
Here is code in columns:
allImages=dir(pwd)
for f=1:size(allImages)
if ~allImages(f).isdir
x2=imread(allImages(f).name);
redChannel = x2(:, :, 1);
greenChannel = x2(:, :, 2);
blueChannel = x2(:, :, 3);
matricaB=[];
A=size(blueChannel)
kolone=A(1)
vrste=A(2)
for i=1:kolone
for j=1:vrste
if redChannel(i,j)~=17 && greenChannel(i,j)~=24 && blueChannel(i,j)~=32
matricaB=[matricaB;redChannel(i,j) greenChannel(i,j) blueChannel(i,j)]
end
end
end
xlswrite('all-files.xlsx', matricaB, f);
end
end

Réponses (1)

Image Analyst
Image Analyst le 27 Nov 2016
You're doing:
xlswrite('all-files.xlsx', matricaB, f);
f is the sheet number, so the data will go into separate sheets. If you want to go into difference cell ranges on the same sheet, then you need to pass in a string with the cell reference:
xlswrite('all-files.xlsx', matricaB, 'A2');
Or you can pass in both the sheet name or number, AND the cell reference.
  2 commentaires
Ivana
Ivana le 27 Nov 2016
It works for first image, but when it comes second, it overwrite columns A2,B2,C2 with values of second image and so on... How to continue numbering cells for next image?
Image Analyst
Image Analyst le 27 Nov 2016
You need to construct the cell reference with sprintf() if it varies:
% Get a reference to the cell.
excelColumn = cell2mat(ExcelCol(startingColumn + columnNumber - 1));
cellReference = sprintf('%s%d', excelColumn, startingRow);
xlswrite('all-files.xlsx', matricaB, cellReference);

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by