Variable index in excel write

1 view (last 30 days)
mayank agrawal
mayank agrawal on 23 Nov 2015
Commented: mayank agrawal on 23 Nov 2015
rating=[1,2,3,4,5,6];
fullFilepathScene=[];
header={'Scene','Mean','Variance','Entropy','Percentage Pixels','ACM','ISE'}
xlswrite('rating',header,'Ratings');
num = xlsread('rating.xls','Ratings')
[index,n]=size(data)
index=index+1
index=(num2str(index));
index=strcat('A',index)
xlswrite('rating',{fullFilepathScene,rating(1),rating(2),rating(3),rating(4),rating(5),rating(6)},'Ratings',index);
The problem is it is writing on the same index.

Answers (1)

Walter Roberson
Walter Roberson on 23 Nov 2015
The only thing you write to the file the first time is the header. Then you use the form of xlsread() that only reads the numeric portion of the data. There is no numeric portion, so num comes out empty, of size 0. You increment that 0 to 1, and so calculate that you want to write in A1 -- which is where the header is.
When you use
num = xlsread(...)
then the data read in from the file is stripped of all leading rows that are come out as completely NaN as numbers, and is stripped of all leading columns that come out as completely NaN as numbers, and is stripped of all trailing columns that come out as completely NaN as numbers. When all there is in the file is the header, that leaves nothing to read.
You should use
[num, txt, raw] = xlsread('rating.xls','Ratings');
[numrows, n] = size(raw);
index = sprintf('A%d', numrows+1);
xlswrite('rating',{fullFilepathScene, rating(1), rating(2), rating(3), rating(4), rating(5), rating(6)}, 'Ratings', index);

Community Treasure Hunt

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

Start Hunting!