0

I'm using this code to take the entered string through text field that is contain text like this( 1,1,1,3,4,7,9,9,9 ) and then I split it depends on , to store each number in array as the result in Matlab but the problem in when I'm using str2double for temp I give error I think I'm using it at the wrong place

code:

points = get(handles.pointstxt,'String');
tmp = regexp(points,'([^ ,:]*)','tokens');
tmp
notesvector = cat(2,tmp{:})

The result appears like this: enter image description here

But I want to make it like this: enter image description here

Samah Ahmed
  • 419
  • 8
  • 24
  • Provide a runnable example and indicate what the error message is in full. Where is `str2double` used? Is `points` just the string `'1,1,1,3,4,7,9,9,9'`? You may be able to use `textscan` to directly convert the string to doubles. – horchler Mar 26 '16 at 22:57
  • I don't want to use textscan because it gives me the result as one cell not like array each number at one cell , about the using of str2double I used it here : notesvector = cat(2,str2double(tmp{:})) but it's wrong because it can't convert all data at the same time ! – Samah Ahmed Mar 26 '16 at 23:56
  • What's wrong with a cell array? If you want convert it to an array just use `double_array = [double_cell_array{:}];`. If you wan't to use `str2double`, pass it a cell array: `str2double(tmp)`. – horchler Mar 27 '16 at 00:02
  • if I make like this : double_array = [notesvector{:}]; for this input text ( 0,0,1,0.2,0.6) the result become like this : 0010.20.6 and it's dealing with each number and floating point as one number – Samah Ahmed Mar 27 '16 at 00:14
  • @horchler it's working now after making str2double(notesvector) , Thank you – Samah Ahmed Mar 27 '16 at 00:26

1 Answers1

0
points = get(handles.pointstxt,'String');
tmp = regexp(points,'([^ ,:]*)','tokens');
notesvector = cat(2,tmp{:})
c = str2double(notesvector)
Samah Ahmed
  • 419
  • 8
  • 24
  • @JeffreyBosboom This is meant to be the complete answer, per [OP's comment](http://stackoverflow.com/q/36240927/#comment60115264_36240927) –  Mar 27 '16 at 03:04