Question about arrays to elements.

1 次查看(过去 30 天)
Portgas Ace
Portgas Ace 2012-9-29
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 个评论
Portgas Ace
Portgas Ace 2012-9-29
what i have to do is to make a base m to base n converter without using built in converter of matlab. so i have to use algorithms and a part of it is by dividing the input value to element per element and solve one by one. and then after having the values for each element, i have to compress it into one element which will then be the final answer.
José-Luis
José-Luis 2012-9-29
编辑:José-Luis 2012-9-29
OK, I am going to give you something your professor probably won't like but it should give you an idea about how to proceed. It won't work for fractional numbers or exponential notation.

请先登录,再进行评论。

回答(3 个)

José-Luis
José-Luis 2012-9-29
a = 0:20;
a = num2str(a);
a = [a(:)'];
a(regexp(a,'[^0-9]')) = [];
  3 个评论
José-Luis
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
Matt Fig 2012-10-1
Oh, I just didn't know if you had something in mind that I missed.

请先登录,再进行评论。


Jan
Jan 2012-9-29
编辑:Jan 2012-9-29
Str = '23456';
Vec = Str - '0';
Now Vec is the corresponding double vector.

Matt Fig
Matt Fig 2012-9-29
编辑:Matt Fig 2012-9-29
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.

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by