How to go through an excel spreadsheet and check cell contents? The code should use the numerical values in cells for calculations. How do I check if the cell is empty or has "N/A" and make the code find the next cell with a numerical value?

%Go through the cells in the excel, i is row index and k column index
% i starts from 2 because the first row is for column headings e.g. height width
% after else should become the calculations that are performed if the cell is not empty % or doesn't have N/A in it.
k = 1;
for i=2:length(Data)
%If the cell is empty or has N/A move to the next one
if (cellfun(@isempty,Data{i,k}) == 1)
i=i+1;
elseif (Data {i,k} == 'N/A')
i=i+1;
else
%calculations
end

回答 (1 件)

dpb
dpb 2015 年 8 月 21 日
Data=xlsread('yourExcelFile.xls'); % read the numeric data; use range if needed
ix=isfinite(Data); % find the numeric values
Data(ix)=calculations(Data(ix)); % operate on those which are finite as desired

質問済み:

2015 年 8 月 21 日

回答済み:

dpb
2015 年 8 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by