readtable excel decimal NaN

3 次查看(过去 30 天)
Johannes Deelstra
Johannes Deelstra 2020-11-5
回答: Priysha LNU 2020-11-11
I use readtable to get access to excel data
some cells in the excell file contain no data and instead have a decimal point,
how can I replace these cells with NaN
regards
Johannes
  2 个评论
Ameer Hamza
Ameer Hamza 2020-11-5
Can you show how these values are loaded in MATLAB?
Johannes Deelstra
Johannes Deelstra 2020-11-5
I use TT=readtable('Skutavr_tapNBTemp94-19_dag.xlsx');
then the data are entered as
'01.05.1994' 0.450000000000000 '1.03' '0.04' '11' '0' '6.6' '1.6' '0.065' '18'
'02.05.1994' 0.360000000000000 '0.59' '0.028' '7' '0.1' '7.9' '0.9' '0.046' '12'
'03.05.1994' 0.310000000000000 '0.34' '0.022' '5' '0' '7.3' '0.5' '0.035' '9'
'04.05.1994' 0.300000000000000 '0.33' '0.021' '5' '0' '9.5' '0.5' '0.034' '9'
because tfhere is a series with no data indicated as
'11.01.1996' 0.110000000000000 '0.04' '0.002' '0' '2.998' '1.1' '0.1' '0.004' '1'
'12.01.1996' 0.160000000000000 '.' '.' '.' '1.996' '0.9' '.' '.' '.'
'13.01.1996' 0.130000000000000 '.' '.' '.' '6.3' '0.9' '.' '.' '.'
'14.01.1996' 0.710000000000000 '.' '.' '.' '3.7' '0.9' '.' '.' '.'
'15.01.1996' 0.590000000000000 '.' '.' '.' '0.1' '0.9' '.' '.' '.'
'16.01.1996' 0.400000000000000 '.' '.' '.' '0' '-0.8' '.' '.' '.'
regards
Johannes

请先登录,再进行评论。

回答(1 个)

Priysha LNU
Priysha LNU 2020-11-11
Hi,
Try using the following code:
[m,n] = size(Data) %gives number of rows and columns in 'Data'
for i = 1:m
for j = 1:n
if strcmp(Data{i,j},'.') %check if cell content is "."
Data{i,j} = NaN %replace with NaN
end
end
end
DISCLAIMER: These are my own views and in no way depict those of MathWorks.

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by