text matrix to scaler matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello I have a matrix such that each cell is a string of numbers example ['10 11 12 13 ';'1 2 3']. I want to convert it into a matrix as[ 10 11 12 13;1 2 3 0]. This matrix contains a text file attachment.I used the function str2num for small matrices but My main work with matrices that have more than one million rows. thank you
kind regards
댓글 수: 2
Azzi Abdelmalek
2013년 12월 23일
Are you sure it's {'10 11 12 13';'1 2 3'} and not {'10 11 12 13' ;'1 2 3 0'}?
답변 (1개)
Azzi Abdelmalek
2013년 12월 23일
v= {'10 11 12 13 ';'1 2 3 0'}
a=cellfun(@(x) cellfun(@str2double,regexp(x,'\d+','match')),v,'un',0);
out=cell2mat(a)
댓글 수: 1
Azzi Abdelmalek
2013년 12월 23일
v= {'10 11 12 13 ';'1 2 3 '}
a=cellfun(@(x) cellfun(@str2double,regexp(x,'\d+','match')),v,'un',0);
n=max(cellfun(@numel,a));
out=cell2mat(cellfun(@(x) [x zeros(1,n-numel(x))],a,'un',0))
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!