Text in a Double array
18 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2019-6-7
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
回答(1 个)
Walter Roberson
2019-6-7
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!