How to prevent .xlsread to turn string data to NaN value
Mostra commenti meno recenti
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.

1 Commento
Andrea Del Rosario
il 8 Gen 2019
Risposta accettata
Più risposte (2)
Cris LaPierre
il 8 Gen 2019
xlsread with a single output only returns numeric data.
- num = xlsread(filename) reads the first worksheet in the Microsoft® Excel® spreadsheet workbook named filename and returns the numeric data in a matrix.
If you want to capture other data types, you have to call it with more output variables.
[num,txt,raw] = xlsread(___)
Walter Roberson
il 8 Gen 2019
Modificato: Walter Roberson
il 8 Gen 2019
0 voti
Use readtable() . If you are using R2016b or later, you can use rmmissing() to remove the table rows with missing entries.
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!