could anyone help me how the numbers can be separated if they are joined together

2 次查看(过去 30 天)
for example 54 is the number i want to separate it into 5 and 4. could anyone please help me on this.

采纳的回答

KSSV
KSSV 2018-3-26
a=54 ;
iwant = [floor(a/10) rem(a, 10)]

更多回答(1 个)

Stephen23
Stephen23 2018-3-26
General solution:
>> num2str(54)-'0'
ans =
5 4
  5 个评论
per isakson
per isakson 2018-3-26
I try to rephrase my question.
Isn't this easier to understand for when coming new to Matlab and computer programming?
Stephen23
Stephen23 2018-3-26
编辑:Stephen23 2018-3-26
"Isn't this easier to understand for when coming new to Matlab..."
Based on questions on this forum (for example some beginners think that '1' has value 1) I don't see any significant benefit in hiding the fact that '1' has value 49 under some unnecessary obfuscation that the character must be first converted to double before it is operated on. I believe the sooner that one learns that ASCII/char values can be manipulated directly the easier it is to work with char arrays, and that most beginners are able to grasp a simple concept like "char arrays can be operated on directly".
"...and computer programming?"
And again judging by questions on this forum, often computer programmers seem to have the hardest time understanding MATLAB, because they come with preconceived ideas of how things should be done. The faster they leave those preconceptions behind and actually learn how MATLAB works, the faster they will learn how to use MATLAB effectively. I don't see how hiding basic MATLAB concepts will help them.
Arrays are the basic MATLAB type, and the ease of array creating, manipulation, and calculations has so far been unsurpassed by any other language (and that includes Julia, which tried very hard). I believe that learning basic numeric/char/cell/struct/... array manipulation concepts will be a benefit to anyone who learns MATLAB, and should in fact be learned as fast as possible, rather than delayed.

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by