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?
Show older comments
%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
Answers (1)
dpb
on 21 Aug 2015
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
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!