2016-03-26 29 views
0

我正在使用此代码通过文本字段包含文本所输入的字符串像这样(1,1,1,3,4,7,9,9, 9)然后我拆分它取决于,作为结果在Matlab中存储每个数组作为结果,但是当我使用str2double为临时的问题我给错误我想我在错误的地方使用它存储字符串后分裂为数组中的数字在Matlab

代码:

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

结果出现这样的: enter image description here

但我想让它像这样: enter image description here

+0

提供一个可运行的例子,并指出该错误信息是充分的。 'str2double'在哪里使用? “点”只是字符串“1,1,1,3,4,7,9,9,9”?您可以使用'textscan'直接将字符串转换为双精度。 – horchler

+0

我不想使用textscan,因为它给我的结果就像一个单元格不像数组中的每个数字一样,关于str2double的使用我在这里使用它: notesvector = cat(2,str2double(tmp {:} )),但它是错误的,因为它不能同时转换所有数据! –

+0

单元阵列有什么问题?如果你想将它转换为数组,只需使用'double_array = [double_cell_array {:}];'。如果你不想使用'str2double',传给它一个单元格数组:'str2double(tmp)'。 – horchler

回答

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

@JeffreyBosboom这意味着是完整的答案,每个[OP的评论](http://stackoverflow.com/q/36240927/#comment60115264_36240927) –