LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

mathscript num2str with formatting

Solved!
Go to solution

In MatLab 2014a I can make the following:

 

mycell = strcat(num2str([1,2,3,7,8,9],'%02d'));

 

it gives:

mycell =

010203070809

 

You can notice how it pre-pended zeros in the text.

 

How do I get that in MathScript, or LabVIEW?

 

Note, I would have asked in the MathScript forum, but that forum is dead.  My previous post there is the 4th most recent, and it is from February. The newest post there is 3 days old and doesn't have a single view or reply. 

0 Kudos
Message 1 of 4
(3,418 Views)
Solution
Accepted by topic author EngrStudent

Capture.PNG

Message 2 of 4
(3,412 Views)

The easiest way to do this is to use precisely the same format (%02d) by passing your numbers into a "format into string" node.

 

Unfortunately these nodes don't handle arrays so you will have to run through a for loop if you want to iterate through the array.

 

Other options include the "number to decimal string" but that won't automatically prepend the zeros, the "number to hexadecimal string" will prepend zeros if you set the minimum width but unfortunately is in hex.

Message 3 of 4
(3,410 Views)

Right, that's a good point. My solution will prepend ANY integer with a 0, %02d will only prepend 0-9 with a 0.

0 Kudos
Message 4 of 4
(3,402 Views)