MATLAB: How to prevent .xlsread to turn string data to NaN value

nanxlsread

Hi there,
I got this code at the moment. I converted my file to .xlsx so I can read my data in matlab. What the forloop does is it goes through the data and goes through cells that contains NaN value then deletes the entire row, resulting in no NaN values in the data set. However, in the end the columns that contained 'string' values turns to NaN value. How do I convert back those NaN values to string values again?
% Reads as xlsx file and contains a forloop that deletes rows that contains
% NaN value - However, when xlsxread is used, the columns that contains strings turns to NaN value.
T = xlsread('testfile4.xlsx');
for col = 6:size(T,2)
i = find(isnan(T(:,col))); %find all row with “NaN” in this col
T(i ,:) = [];
end
This is what it looks like after deleting the rows with NaN values. Now the second and third columns contains NaN values which was strings before.
sampleData7.PNG

Best Answer

MATLAB doesn't give the option to store 'string' and 'double' in an double array. You can read the excel file and store it in a 'cell' array. You can try this :
[number,string,everything]=xlsread('testfile4.xlsx');
for col=5:2:size(everything,2)
rind=find(number(:,col)==0);
everything(rind+1,:)=[]; % '+1' because there are names in 1st row
end
I hope this helps