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
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!