# How Can I plot a cell array against a double

6 visualizzazioni (ultimi 30 giorni)
Farshid Daryabor il 18 Gen 2024
Commentato: Voss il 18 Gen 2024
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 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Farshid Daryabor il 18 Gen 2024
Spostato: Stephen23 il 18 Gen 2024
please find the attached seasonal data, Thanks

Accedi per commentare.

### Risposta accettata

Voss il 18 Gen 2024
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 = 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 CommentiMostra 4 commenti meno recentiNascondi 4 commenti meno recenti
Farshid Daryabor il 18 Gen 2024
Thanks!
Voss il 18 Gen 2024
You're welcome!

Accedi per commentare.

### Categorie

Scopri di più su Calendar in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by