1

这是我的代码:

%% 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)

我收到的错误消息说:

使用 plot Conversion to double from cell 时出错是不可能的。

Evergladesprecipushdcn(第 28 行)绘图中的错误(datenums,everglades_precip_data)

请帮忙!

4

1 回答 1

6

你可以用这个来修复它:

plot(datenums,[everglades_precip_data{:}]);

或这个:

plot(datenums,cell2mat(everglades_precip_data));
于 2013-07-02T14:18:33.850 回答