Spliting Cell Into Multiple Columns
古いコメントを表示
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 件のコメント
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
2018 年 9 月 5 日
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
2018 年 9 月 5 日
編集済み: Quang Phung
2018 年 9 月 5 日
Stephen23
2018 年 9 月 6 日
@Quang Phung: exactly which data do you need to import from that file? Can you please show us which values you need.
Quang Phung
2018 年 9 月 6 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!