Spliting Cell Into Multiple Columns
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
You can probably avoid a lot of headache if you import the data properly, in this step:
TCOMP_CELL = textscan(FileID,'%s','Delimiter','\n');
if you attach the data it's easier to help you. In the meantime you can try readtable which often figures out how to import tabular data without additional inputs.
Quang Phung
il 5 Set 2018
I'll take a look. textscan is probably the most flexible input option but also one of the more difficult ones to master. I'd consider myself novice :)
Can you explain exactly what you want to store from this text? It seems to have one big table and some smaller ones.
EDIT: I'll have a look when I wake up tomorrow if no one helped you by that time. This is probably the most complex table I've ever tried to import.
Quang Phung
il 5 Set 2018
Modificato: Quang Phung
il 5 Set 2018
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.
Quang Phung
il 6 Set 2018
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Characters and Strings in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!