store 2 fields of a structure in a loop

4 views (last 30 days)
Tala Hed
Tala Hed on 27 Feb 2019
Commented: Tala Hed on 28 Feb 2019
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 Comments
Bob Thompson
Bob Thompson on 27 Feb 2019
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 on 28 Feb 2019
No particular reason, just more vissually appealing...
I cannot find the "accept" button to press tho !
Thanks for your time

Sign in to comment.

Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!