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