这是我的代码:
%% Load and plot precipitation data
%Read the salinity data file
fid = fopen('Everglades Precip USHDCN.csv');
%Read the salinity data file
everglades_ushcn_data = textscan(fid, '%f %*f %f %*s %f f', 'HeaderLines',2, 'Delimiter', ',');
%Close the data file
fclose(fid);
%Precip data is in the 2nd column
everglades_precip_data = everglades_ushcn_data(:, 4);
%Convert everything to a matrix
matrix_data = cell2mat(everglades_ushcn_data);
%Convert a date vector to a date number
datenums = datenum(matrix_data(:, 3:-1:1));
%Select dates
everglades_precip_year = everglades_ushcn_data{3};
%Plot surface precip data
figure
plot(datenums,everglades_precip_data)
%Convert the x axis to label date
datetick(gca)
xlabel ('Date', 'Fontsize', 14)
ylabel('Precipitation', 'Fontsize', 14)
title('Everglades Precipitation', 'Fontsize', 16)
我得到的错误信息是:
使用绘图时出错 无法从单元转换为双倍。
Evergladesprecipushdcn出错(第28行) 情节(datenums,everglades_precip_data)
请帮助!
答案 0 :(得分:6)
你可以解决这个问题:
plot(datenums,[everglades_precip_data{:}]);
或者这个:
plot(datenums,cell2mat(everglades_precip_data));