Monday, March 08, 2010

Matlab: Convert numerical array to cell with string representation of numbers

Short Matlab script that takes an array (i.e. vector) of numbers and returns cell with fileds that are string representation of the numbers in the array.For example: >> a=[1 2 3.24 -43 4.56];
>> numarray2cellstring(a)

ans =

'1' '2' '3.24' '-43' '4.56'

2 comments:

  1. Anonymous3:56 PM

    It's better to use regexp(arrayOfStringNumbers, '\s*', 'split'). This avoids for loops.

    ReplyDelete
  2. Anonymous5:19 AM

    Thank you very much :)
    I couldn't find any other way to make this command work!

    set(gca,'XTickLabel',numarray2cellstring(indexes))
    it works only with a cell with strings inside.

    Thanks again

    ReplyDelete