Text in a Double array
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a 12x301 double matrix where the first column is all zeroes and the rest are numerical data. I am trying to get dates to show up in the first column, but apparently you can't insert characters or strings into a double matrix (error message: Subscripted assignment dimension mismatch). I am using Matlab 2011, any help would be greatly appreciated.
4 Kommentare
Walter Roberson
am 7 Jun. 2019
Hold your dates in a separate cell array of character vectors. Do your numeric manipulation as needed. Just before writing out, use
datacell = [YourCellOfDates, num2cell(YourNumericData)];
now xlswrite datacell
Antworten (1)
Walter Roberson
am 7 Jun. 2019
You cannot do that with a double array if the dates are represented as characters; you would have to represent the dates numerically such as 201705221933 for May 22 2017 19:33
In R2013b, the table() datatype was created that permits mixed data types in a tabular form.
You could create a cell array, but the display will probably be a bit ugly:
[{'07-Jun-2019'}, num2cell(1:10)]
ans =
1×11 cell array
{'07-Jun-2019'} {[1]} {[2]} {[3]} {[4]} {[5]} {[6]} {[7]} {[8]} {[9]} {[10]}
(The display in your release did not have all of those {} wrappers)
You need to decide the circumstances under which the dates have to be readable. If this is for display onto the graphics window then you could use uitable() . If this is for writing in a file, then you would use fopen() / fprintf() / fclose with appropriate formats, with a loop sometimes being the easiest way to get the formats right. If this is for display to the command window, then write a small routine that does the formatting for you using fprintf() . But if this has to show up nicely when using the variable browser or when using disp() then you have a problem unless you use the numeric date forms.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!