필터 지우기
필터 지우기

array of strings into 2 number array

조회 수: 5 (최근 30일)
fima v
fima v 2017년 2월 17일
댓글: Walter Roberson 2017년 2월 17일
Hello, i have an array of 3 strings,each string is consists of two numbers spaced by tab. i would like to create a 2X3 2D array.i thought of going with for loop using strsplit and str2num. is there an easier way,without for loop?
Thanks
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 2월 17일
Is this a cell array of strings, or a char array?

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 2017년 2월 17일
str = {'apple' 'boy'} ; % you may take numbers
repmat(str,2,3)
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 2월 17일
? This does not appear to be related to the needs of the Question ?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 2월 17일
TAB = sprintf('\n');
output = str2double( cellfun(@(S) strsplit(S, TAB), YourCell, 'Uniform', 0) );
or
temp = regexp(YourCell, '\t', 'split');
output = str2double( vertcat(temp{:}) );

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by