Expand nested cell array
Mostrar comentarios más antiguos
Hello,
I have a cell array that is a 35x1 cell. within each cell, is a nested "1x7" cell array. How can I expand this so that there are no nested arrays (no multilevels)? I am very very new to matlab so not familiar with everything. But, from what I read, textscan can help with this. However the issue is that my input is user defined - meaning it can have any number of rows and columns. So I don't quite know what else to do except what I tried here. But this gives me the nested arrays...Any help would be really appreciated!
filename = 'C:\------------\test_1.txt';
%% Open the text file.
fileID = fopen(filename,'r');
m=1;
while ~feof(fileID)
line = fgetl(fileID);
row{m,1}=line;
m=m+1;
end
row2=strtrim(row);
C={zeros};
%row2=strtrim(row(2,1));
for i=1:m-1
C{i,1}=strsplit(row2{i}, ' ');
end
%C=strsplit(row2{1}, ' ');
fclose(fileID);
The input (which includes text and numbers) in text file looks like the following. There are no headers. The user can add another set of data for say U238 below last line here. It will follow the same format though.
U235
NU FISSION CAPTURE GAMMA ELASTIC INELASTIC N2N
-3.641533E-06 -3.044039E-06 -1.348232E-06 -1.348232E-06 -3.950710E-07 -3.324834E-07 -2.245561E-07
-6.166287E-05 -5.457152E-05 -3.022275E-05 -3.022275E-05 -3.027813E-06 -1.243815E-06 -2.365025E-06
4 comentarios
Walter Roberson
el 31 de Dic. de 2018
U235
Will there ever be a number before the element symbol, such as representing an element? Or will it ever list a compound
Are the column names fixed or can they differ?
Ishita Trivedi
el 31 de Dic. de 2018
Walter Roberson
el 31 de Dic. de 2018
I notice that you talk about cells that are 1 x 7, and I notice that you have 7 columns of input in your sample file. I presumed the 1 x 7 referred to the 7 different columns. If that is the case and if other files might have more or fewer columns, then they could potentially lead to cells that were size different than 1 x 7, and so 35 x1 of those could not be combined to make 35 x 7.
So, considering that the number and meaning of the columns could differ, then what organization would make sense for you to avoid multiple levels of cell arrays?
Viren Gupta
el 2 de En. de 2019
Do you mean to say that each row may have different lengths? Also could you explain better what do you mean by not having multi-levels and which kind of organization you want?
Respuestas (0)
Categorías
Más información sobre LaTeX en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!