converting a specific string to two fractions
이전 댓글 표시
I'm trying to write a function that takes as input a string in the form of '12/345' and would return two integers:
numerator = 12
denominator = 345
답변 (2개)
Wayne King
2011년 10월 23일
One way:
inputfrac = '12/345';
loc = find(ismember(inputfrac,'/')==1);
num = str2num(inputfrac(1:loc-1));
den = str2num(inputfrac(loc+1:end));
댓글 수: 1
Walter Roberson
2011년 10월 23일
The find is not needed in the above:
[tf, idx] = ismember(inputfrac,'/');
loc = idx(tf);
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!