|
Hi,
I am importing CSV files. Matlab is giving me the option to replace non numeric cells by a specific value such as zero or nan. However, I want to have the option to assign multiple values depending on the content of the cell . For example: one column (which is column 13 of an 87000x15 Matrix" contains "T" or "C" or "CR" values and I want to tell matlab if the non mumeric value is "T" then assign the numeric value "1" , if it is "C" assign "0", if it is "CR" assign "2". I am wondering how I can modify the matlab script to get this option. The script auto-generated by Matlab contain the following:
%% Import data from spreadsheet
% Script for importing data from the following spreadsheet:
%
% Workbook: C:\Users\Joseph\Documents\MATLAB\CS\CSV\1.csv Worksheet: 1
%
% To extend the code to different selected data or a different spreadsheet,
% generate a function instead of a script.
% Auto-generated by MATLAB on 2012/07/06 17:23:27
%% Import the data, extracting spreadsheet dates in MATLAB datenum format
[~, ~, raw, dateNums] = xlsread('C:\Users\Wassim\Documents\MATLAB\CS\CSV\1.csv',num2str(i),'','',@convertSpreadsheetDates);
raw = raw(2:end,4:end);
dateNums = dateNums(2:end,4:end);
%% Replace date strings by MATLAB datenums
R = ~cellfun(@isequalwithequalnans,dateNums,raw) & cellfun('isclass',raw,'char'); % Find Excel dates
raw(R) = dateNums(R);
%% Replace non-numeric cells with 0.0
R = cellfun(@(x) ~isnumeric(x) || isnan(x),raw); % Find non-numeric cells
raw(R) = {0.0}; % Replace non-numeric cells
%% Create output variable
untitled = cell2mat(raw);
%% Clear temporary variables
clearvars raw dateNums R;
Thanks
|