Variable index in excel write
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Walter Roberson
2015-11-23
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);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!