store 2 fields of a structure in a loop

1 次查看(过去 30 天)
I have an array (79*15). The length of each column is different. (attached).
I want to read column 1, use that as the input of a function (attached) which output is a structure with 10 fields. Store 2 of those fields and then read the next column of my data. Can you please help me...
for i=1:15
stats=allfitdist(Matlab_Sl(:,i),'PDF');
% now create a new variable or cell
% store stats.DistName and stats.BIC in 2 first columns of the new variable and done!
% go read the second column of Matlab_Sl, do the same and store stats.DistName and stats.BIC in columns 3 and 4
% and so on to the last column
end
  15 个评论
Bob Thompson
Bob Thompson 2019-2-27
Is there a particular reason why you don't want to keep the results in a strucuture? You could just index the results of the structure to keep all results from the different input columns and you will probably have a much easier time of things.
stats(:,i) = allfitdist(Matlab_Sl(:,i),'PDF');
If you really don't want to do this then you will need to concat the different results from all of your structure values together. I don't know off the top of my head how the indexing would work to enter the different structure elements into individual cells without a loop. Concatonating the results into one cell would just result in a cell which contains either one large array, or a structure with multiple elements but only one field.
Additionally, my previous responses where using the assumption that both DistName and BIC were arrays of doubles. Because these two fields contain different classes of data the only ways to store then in a single variable would be using cells, structures, or tables. This is another reason why I ask why you are looking to move the data out of a strucutre array.
Tala Hed
Tala Hed 2019-2-28
No particular reason, just more vissually appealing...
I cannot find the "accept" button to press tho !
Thanks for your time

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by