Matlab中单元格逻辑索引的问题

Elp*_*rto 2 matlab

我正在从URL中读取数据,解析它,然后尝试进一步格式化数据:

year = 2008;
month = 9;
day = 30;

raw = urlread(sprintf('http://www.wunderground.com/history/airport/KCVS/%i/%i/%i/DailyHistory.html?HideSpecis=0&theprefset=SHOWMETAR&theprefvalue=0&format=1',year,month,day));
data = textscan(raw,'%s %s %s %s %s %s %s %s %s %s %s %s','Delimiter',',','HeaderLines',2,'CollectOutput',true);

dir = data{1}(1:end-1,7);
wind = cellfun(@str2num,data{1}(1:end-1,8),'UniformOutput',false);
gust = cellfun(@str2num,data{1}(1:end-1,9),'UniformOutput',false);

wind{cellfun(@isempty,wind)} = 0;
gust{cellfun(@isempty,gust)} = 0;
Run Code Online (Sandbox Code Playgroud)

现在wind{cellfun(@isempty,wind)} = 0;可以工作,但gust{cellfun(@isempty,gust)} = 0;我得到这个错误说:??? 这项任务的右侧数值太少,无法满足左侧的要求.cellfun(@isempty,gust)正确返回逻辑数组.也gust{1} = 0将正常工作.为什么它适用于风而不是阵风?

Amr*_*mro 5

这是一种更好的解析数据的方法:

year = 2008; month = 9; day = 30;

%# get raw data
urlStr = sprintf('http://www.wunderground.com/history/airport/KCVS/%i/%i/%i/DailyHistory.html?HideSpecis=0&theprefset=SHOWMETAR&theprefvalue=0&format=1',year,month,day);
raw = urlread(urlStr);

%# collect data and headers
raw = strrep(raw, '<br />', '');        %# remove HTML <br/> at end of each line
raw = textscan(raw,repmat('%s ',1,12), 'Delimiter',',', 'HeaderLines',1, 'CollectOutput',true);
headers = raw{1}(1,:);
data = raw{1}(2:end-1,:);

%# extract certain columns
A = data(:,7);                %# cell array of strings
B = str2double(data(:,8:9));  %# numeric data
B( isnan(B) ) = 0;
Run Code Online (Sandbox Code Playgroud)

哪里:

>> B
B =
          5.8            0
          5.8            0
          5.8            0
            0            0
            0            0
          5.8            0
          4.6            0
            0            0
          3.5            0
          4.6            0
          6.9            0
          9.2         17.3
         12.7         20.7
         13.8         19.6
           15            0
         11.5            0
         11.5            0
          9.2            0
          8.1            0
          9.2            0
          9.2            0
          9.2            0
         10.4            0
         10.4            0
Run Code Online (Sandbox Code Playgroud)