如果我理解你的問題的第一部分,你想刪除 newfile 單元格數組中只包含空單元格的任何行 . 您可以使用函數CELLFUN來查找空單元格,使用函數ALL查找包含所有空單元格的行,然后使用logical indexing刪除這些行:
>> newfile = cell(5,5); %# Empty cell array
>> newfile(:) = {''}; %# A different way to assign values without DEAL
>> newfile([1 2 4 5]) = {'a'} %# Make some non-empty cells
newfile =
'a' '' '' '' ''
'a' '' '' '' ''
'' '' '' '' ''
'a' '' '' '' ''
'a' '' '' '' ''
>> emptyIndex = cellfun('isempty',newfile) %# Logical index of empty cells
emptyIndex =
0 1 1 1 1
0 1 1 1 1
1 1 1 1 1
0 1 1 1 1
0 1 1 1 1
>> newfile = newfile(~all(emptyIndex,2),:) %# Removes 3rd row
newfile =
'a' '' '' '' ''
'a' '' '' '' ''
'a' '' '' '' ''
'a' '' '' '' ''
EDIT: 如果使用空格( ' ' )而不是空字符串( '' )初始化單元格數組 newfile ,則必須在上面的代碼中更改計算 emptyIndex 的方式 . 應將CELLFUN參數 'isempty' 更改為 @(x) strcmp(x,' ') 以獲得相同的結果 .
關于第二個問題,您可以在調用XLSWRITE中指定要添加數據的文件中的工作表和行/列范圍 . 如果您每天添加一次文件,最簡單的解決方案可能是添加一個以日期作為名稱的新工作表 . 以下內容將 M 中的數據寫入文件 fileName ,添加一個以當前日期和時間命名的新工作表:
xlswrite(fileName,M,datestr(now));
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态