MATLAB Answers

Why i am getting Nan?

Tsvetan Terziev 님이 질문을 제출함. 7 May 2019
최근 활동 Walter Roberson 님이 답변함. 7 May 2019
I'm trying to download the weather forecast from a site.
close all
clear all
%%download weather forecast data from server
%for most recent file use last index in relev_files
% ta_url=['',current_files(relev_files(1:end)-21:relev_files(1:end)+20)];
%%put forecast data into vectors
C = [strsplit(ta_data, '\n')]' ;
D = char(C(2:end-1));
for I = 1:numel(D,1)
E = strsplit(D(I,:));
month(I) = str2double(char(E(1,2)));
F =char( E(1,3));
G = strsplit(F, 'T');
day(I) = str2double(char(G(1,1)));
H = char(G(1,1));
J = strsplit(H, ':');
hour(I) = str2double(char(J(1,1)));
min(I) = str2double(char(J(1,2)));
K = J{1,1};
L = strsplit(K, 'Z');
sec(I) = str2double(char(L(1,1)));
M = L{1,1};
N = strsplit(M, ',');
value(I) = str2double(char(N(1,1)));
%F = strsplit(D(1,:), 'T')
data=[year' month' day' hour' min' sec' value'];
t = datetime(year, month, day, hour, min, sec);
plot(t, value, '*')
hold on
plot(t, value, '-k', 'Linewidth', 2)
axis tight, grid minor
ylabel('Temperature (°C)')

  댓글 수: 1

Adam 7 May 2019
Getting NaN where? You create about 24 variables in that code.

로그인 to comment.


답변 수: 2

Cam Salzberger 님의 답변 7 May 2019
Cam Salzberger 님이 편집함. 7 May 2019

Any time str2double is unable to translate a particular input into a number, it returns NaN. That is probably where the issue is occuring, so consider checking the inputs more carefully. Also, numel generally takes just one input. I think you meant to use size(D, 1).

  댓글 수: 0

로그인 to comment.

Walter Roberson 님의 답변 7 May 2019

There is no year in any line until after line 1800.

  댓글 수: 0

로그인 to comment.

Translated by