Spliting Cell Into Multiple Columns
58 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have been having issues separating my cell data into multiple columns. But I seem to be encountering problems with trying to split my 1 column cell data into 4 columns.
I have attached my code below:
%%Data Import:
% Open File:
FileID = fopen('TCOMP244.TXT');
% Read File
TCOMP_CELL = textscan(FileID,'%s','Delimiter','\n');
% Close File:
fclose(FileID);
% Data Extraction:
DATA_CELL=TCOMP_CELL{1,1};
%%Data Extraction:
% Iteration Initialization:
[k, j, l, m, o, p, r] = deal(1, 1, 1, 1, 1, 1, 1);
% Cell Initialization:
Primary_Chain = cell((ceil((length(DATA_CELL)-182)./89).*20),1);
Primary_Am_Chain = cell((ceil((length(DATA_CELL)-211)./89).*15),1);
Secondary_Am_Chain = cell((ceil((length(DATA_CELL)-235)./89).*15),1);
%%Primary Fission Chain:
for i=182:89:length(DATA_CELL)
for k=0:19
Primary_Chain{j,1} = DATA_CELL{i+k};
j = j+1;
end
end
%%Principal Americium Chain:
for l=211:89:length(DATA_CELL)
for n=0:14
Primary_Am_Chain{m,1} = DATA_CELL{l+n};
m = m+1;
end
end
%%Secondary Americium Chain:
for o=235:89:length(DATA_CELL)
for q=0:14
Secondary_Am_Chain{p,1} = DATA_CELL{o+q};
p = p+1;
end
end
This leads to following output:
What should I do to separate the cell into multiple columns.
*My intent is to take the latter 3 columns and convert them into a floating point matrix for use in a separate calculation.
Thanks in advance.
6 Commenti
Stephen23
il 6 Set 2018
@Quang Phung: exactly which data do you need to import from that file? Can you please show us which values you need.
Risposta accettata
Robert U
il 6 Set 2018
Hello Quang Phung,
for your data "Primary_Chain" you could use the following code fragment in order to
- seperate the columns inside cell
- delete 1st column
- convert to array of double
% separate columns
Test = cellfun(@(cIn) strsplit(cIn,' ')',Primary_Chain,'UniformOutput',false);
Test = [Test{:}]';
% delete first column
Test(:,1) = [];
% convert to double
TestOut = cellfun(@str2num,Test);
Kind regards,
Robert
2 Commenti
Robert U
il 7 Set 2018
- strplit() with delimiter ' '(space) is applied to each cell of cell array Primary_Chain
- output is a cell array again that contains the strings split to cells
- recover sub-cells via calling all sub-cells and collect in an array (to not loose structure mind the transpose()-command twice, once within cellfun() and next after data has been collected
- delete first column straight forward
- apply str2num() to each cell of Test, output will be numeric array of doubles
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Big Data Processing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!