Info

此问题已关闭。 请重新打开它进行编辑或回答。

Writing few data in Excel in one sheet

1 次查看(过去 30 天)
Ivana
Ivana 2016-11-27
关闭: MATLAB Answer Bot 2021-8-20
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 个评论
Ivana
Ivana 2016-11-27
编辑:Walter Roberson 2016-11-27
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

回答(1 个)

Image Analyst
Image Analyst 2016-11-27
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 个评论
Ivana
Ivana 2016-11-27
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 2016-11-27
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);

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by