Save each loop from getfield command

1 view (last 30 days)
Tanita M Frey
Tanita M Frey on 2 Feb 2023
Commented: Tanita M Frey on 3 Feb 2023
Hello everyone,
I have been trying to extract and combine data from a prior file named "fftrials". It is a 2x4 cell array containing 2x43 structure arrays including the .df information (which is the one of interest here). Each .df file contains a 111x56 single matrix representing therefore 56 cells and their responses in 111 trials.
The 43 represents the repetition of the same cell response for the same tone, which I want to mean over each row of each cell (column).
As of for now, I am only able to extract the .df part of those structures in a loop manner. However, I fail at saving each of n step, let alone to create an average for all of those.
Here the code of me attempting the saving:
extractdelta = zeros(111,56); % as most forums and tutorials say that is the most efficient way to replace and create a new matrix for the loop
for n=1:size(fftrials {1,1},2); % in this case it equals to 1:43
ffextract = getfield (fftrials {1,1} (1, n), 'df');
extractdelta(n) = ffextract % this step fails due to the error: "Unable to perform assignment because the left and right sides have a different number of elements. " - which is confusing, because both are 111x56 after one run
end
I like to mention that if I mute "extractdelta(n)", the saved ffextract is saving the data of the 43rd repetition as a 111x56 single.
Hence, my first question now, how could I save each of the ffextracts as a separate matrix? Or even better in one array?
Following question would relate to recommendations how to insert the calculation of the mean for all the repetitions (43) and then save that output as one matrix(111x56 single)?
I would appreciate any help. Thank you for taking your time (even if only reading this).
Best wishes

Answers (1)

Walter Roberson
Walter Roberson on 2 Feb 2023
It is not clear to me why you are using that getfield instead of
ffextract = fftrials{1,1}(1,n).df;
You have
for n=1:size(fftrials {1,1},2)
so at any one point, n is a scalar.
extractdelta(n) = ffextract
n is a scalar, so extractdelta(n) designates a scalar destination. You indiate that ffextact is 111 x 56; that is not going to fit inside a scalar destination.
  3 Comments
Walter Roberson
Walter Roberson on 3 Feb 2023
iters = size(fftrials {1,1},2);
extractdelta = zeros(111, 56, iters);
for n = 1 : iters
....
extractdelta(:,:,n) = ffextract;
end
Tanita M Frey
Tanita M Frey on 3 Feb 2023
that works wonderfully, thank you so much!

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!