please find the attached seasonal data, Thanks
How Can I plot a cell array against a double
8 次查看(过去 30 天)
显示 更早的评论
Please find the attached file. I have a vector(1*40), double, that include years since 1982 to 2021, and monthly temperature data corresponding to each year in a cell (1*40). how can I plot a timeseries of temperature, so that the x-axis has to be specified the values of each year with the label of the corresponding year. thanks if someone answer my question.
采纳的回答
Voss
2024-1-18
Your monthly temperature data has two cells containing vectors of only 11 elements. There is no way to tell, with just the information given, which month's data is missing in those cases. Here I'll assume the months with missing data are at the end of the year, and append NaNs at the end of any vector whose length is less than 12.
S = load('1d_data.mat')
% make a datetime vector representing the 1st of each month for all S.years:
[YY,MM] = meshgrid(S.years,1:12);
DT = datetime(YY(:),MM(:),1);
% append NaNs to any vector in S.var that has fewer than 12 elements:
for k = 1:numel(S.var)
S.var{k}(end+1:12) = NaN;
end
% plot:
plot(DT,vertcat(S.var{:}))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!