how to plot date(the format of the date is cell)
Afficher commentaires plus anciens
I read the data from an Excel file. This file contains dates of a series of price data. But the format of the date is cell. When I use cell2mat to convert the date, Matlab just gives me back an error :
cell2mat(date2) ??? Error using ==> cat CAT arguments dimensions are not consistent.
Error in ==> cell2mat at 89 m{n} = cat(1,c{:,n});
date2 is the name of the cell contain dates. I tried to use a loop, I got another error
for i = 1:81
k(i) = cell2mat(date2(i));
end
??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
The date is of following format
'2012/3/27' '2012/3/28' '2012/3/29' '2012/3/30' '2012/4/5' '2012/4/6' '2012/4/9' '2012/4/10' '2012/4/11' '2012/4/12'
1 commentaire
You should provide the date2 variable... !
your date2 should be like "yourpricedate" as mentioned by andrei! if so the first error "cat" wont be there...
whereas you might have used something like date2=['2012/3/27' ; '2012/3/28' : ...so on] ! if this is the case the operator ";" tries to Concatenate....!
Secondly in the loop
cell2mat (date(i))
will return a numeric array and for this case its a string and you can't put in the whole string or array into k(so n so) and to plot date what you have tried is not so clear...!
The following command would help you on working for dates!!!
In Matlab - Help - Product Help
datestr
datenum
Réponses (1)
Andrei Bobrov
le 27 Juil 2012
yourprice=randi(25,10,1);
yourpricedate = {'2012/3/27' '2012/3/28' '2012/3/29'...
'2012/3/30' '2012/4/5' '2012/4/6' '2012/4/9'...
'2012/4/10' '2012/4/11' '2012/4/12'};
plot(A)
set(gca,'XTickLabel',yourpricedate);
Catégories
En savoir plus sur Dates and Time dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!