Question about arrays to elements.
古いコメントを表示
Sprintf makes an element into an array. is there an inverse function to this? for example array [ 2 3 4 5 6] = 23456
it should be a single element because our prof wont allow us to have an output of an array.
回答 (3 件)
José-Luis
2012 年 9 月 29 日
a = 0:20;
a = num2str(a);
a = [a(:)'];
a(regexp(a,'[^0-9]')) = [];
3 件のコメント
Matt Fig
2012 年 9 月 29 日
What is the difference between your code and:
a = 0:20;
a = sprintf('%i',a);
José-Luis
2012 年 10 月 1 日
None really, but this was a homework question and I didn't want to give a direct answer. In hindsight, I can see that my answer was a tad misguided.
Matt Fig
2012 年 10 月 1 日
Oh, I just didn't know if you had something in mind that I missed.
Str = '23456';
Vec = Str - '0';
Now Vec is the corresponding double vector.
I think the question is a little unclear, so I will go in a circle:
A = [2 3 4 5 6] % Start here
A2 = str2double(sprintf('%i',A)) % One element
A3 = num2str(A2)-'0' % Back to the beginning.
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!