Clear Filters
Clear Filters

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

2 views (last 30 days)
for example 54 is the number i want to separate it into 5 and 4. could anyone please help me on this.

Accepted Answer

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

More Answers (1)

Stephen23
Stephen23 on 26 Mar 2018
General solution:
>> num2str(54)-'0'
ans =
5 4
  5 Comments
per isakson
per isakson on 26 Mar 2018
I try to rephrase my question.
Isn't this easier to understand for when coming new to Matlab and computer programming?
Stephen23
Stephen23 on 26 Mar 2018
Edited: Stephen23 on 26 Mar 2018
"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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!