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
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')
S = struct with fields:
var: {1×40 cell} years: [1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 … ] (1×40 double)
% 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{:}))
  6 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by