Filter löschen
Filter löschen

text matrix to scaler matrix

1 Ansicht (letzte 30 Tage)
min ho lee
min ho lee am 23 Dez. 2013
Kommentiert: Azzi Abdelmalek am 23 Dez. 2013
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 Kommentare
Azzi Abdelmalek
Azzi Abdelmalek am 23 Dez. 2013
Are you sure it's {'10 11 12 13';'1 2 3'} and not {'10 11 12 13' ;'1 2 3 0'}?
min ho lee
min ho lee am 23 Dez. 2013
Yes, I'm sure. I've attached the input and output matrices. Output matrix was created by hand, but for large data sets it is not logical.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 23 Dez. 2013
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 Kommentar
Azzi Abdelmalek
Azzi Abdelmalek am 23 Dez. 2013
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))

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by