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