Writing string into array
古いコメントを表示
Hi,
I'm trying to write strings into an array, but for some reason it's not working as expected (and has been working perfectly in other code I have)
So I have in a for loop:
newtimearray(n,:)=[datestr(timestamp,'yy') datestr(timestamp,'mm')...
datestr(timestamp,'dd') datestr(timestamp,'HH') datestr(timestamp,'MM')...
datestr(timestamp,'ss') strcat(fileID,'-',num2str(chunkCnt),'.bin') 'normal'];
However, instead of saving every entry into a single cell, it merges everything into one single string.
newtimearray =
16051512100100000000-6.binnormal
16051512400100000001-6.binnormal
16051513100100000002-6.binnormal
As I said, similar code is working fine and I don't see the error.
Thanks :)
2 件のコメント
per isakson
2016 年 8 月 20 日
With which releases (of Matlab) did it work and with which did it not?
per isakson
2016 年 8 月 20 日
回答 (2 件)
Image Analyst
2016 年 8 月 20 日
0 投票
You're writing them into a regular character array because you used square brackets, not into a cell array, which requires braces. To see the differences and to learn when to use braces, brackets, and parentheses, see the FAQ: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
2 件のコメント
Anke Kügler
2016 年 8 月 20 日
Image Analyst
2016 年 8 月 25 日
What kind of array do you want, a cell array, or a character array? And tell me what "timestamp" is.
Anke Kügler
2016 年 8 月 20 日
編集済み: Anke Kügler
2016 年 8 月 20 日
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!