How Can I plot a cell array against a double

조회 수: 6 (최근 30일)
Farshid Daryabor
Farshid Daryabor 2024년 1월 18일
댓글: Voss 2024년 1월 18일
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.
  댓글 수: 1
Farshid Daryabor
Farshid Daryabor 2024년 1월 18일
이동: Stephen23 2024년 1월 18일
please find the attached seasonal data, Thanks

댓글을 달려면 로그인하십시오.

채택된 답변

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
Farshid Daryabor
Farshid Daryabor 2024년 1월 18일
Thanks!
Voss
Voss 2024년 1월 18일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by