Extract data from Table by using data in a Cell

2 views (last 30 days)
Dear all,
I have been using MATLAB for 4 days now, so please bear with me if I ask very trivial question.
I work on data acquisition analysis. Data comes from a Fatigue Test of an aeronautical component.
AllStrains Table (607 x 28514 double) contains strains(numbers), 607 rows are the number of strain gauges and 28514 columns are the time stamps (1:28514). Visualise this as a table with x,y values.
I want to extract strains (from AllStrains table) for a specific time window. The time window is a collection of ranges of time stamps e.g. 1069 to 1456, 1457 to 1985...etc, which does not have the same length for each time window e.g. first time window has 364 time stamps, second 120 time stamps, 3rd 874 time stamps......
I have created a loop to create the time windows as Turn_Points_Ranges as a cell, (843,1 cell), where 843 are the number of time windows I need to extract the strains from the AllData table.
Result of this process should be another cell same size as the Turn_Points_Ranges, obviously, which has the respective strains (from the AllData table) for the corresponding time windows stored in the Turn_Points_Ranges.
Concluding, I need to find a way to create a cell/matrix/table (apologies if I am mixing irrelevant terminology, but at the moment everything seems similar to me) from data stored in A table by indexing the relevant information by data stored in a cell B.
I have attached part of my script:
You can see some of my attempts in Green, which do not work.
Usual ERROR "Subscripted assignment dimension mismatch."
I can run though the following:
>> Out1=cell2mat(Turn_Points_Ranges([1]));
>> Strn1=AllStrains(1,Out1);
>> plot(Strn1)
Just need to automate the above. Any help/tip is more than welcome. Thanks in advance.

Accepted Answer

Guillaume
Guillaume on 21 Jul 2015
Using your Turn_Points_Ranges and cellfun:
windowedstrains = cellfun(@(tpr) AllStrains(:, tpr), Turn_Points_Ranges, 'UniformOutput', false)
which, if you're uncomfortable with cellfun and anonymous functions is equivalent to:
windowedstrains = cell(size(Turn_Points_Ranges));
for iter = 1:numel(Turn_Points_Ranges)
tpr = Turn_Points_Ranges{iter};
windowedstrains{iter} = AllStrains(:, tpr);
end
Or you could bypass your creation of Turn_Points_Ranges altogether and just do:
windowedstrains = arrayfun(@(tp1,tp2) AllStrains(:, tp1-5:tp2+5), Turn_Points(1:end-1), Turn_Points(2:end), 'UniformOutput', false)
which as a loop would be:
windowedstrains = cell(numel(Turn_Points)-1);
for iter = 1:numel(Turn_Points)-1
windowedstrains{iter} = AllStrains(:, TurnPoints(iter)-5:Turn_Points(iter+1)+5);
end
  2 Comments
Yanis
Yanis on 22 Jul 2015
Thanks Guillaume, I used your bottom solution, just changed the windowestrains cell to only have 1 column as anything after column 1 was empty.
windowedstrains=cell(numel(Turn_Points)-1,1);
Thanks for your help again.
Guillaume
Guillaume on 23 Jul 2015
Yes, sorry that was a mistake from my part. That's why I prefer cellfun / arrayfun. They automatically take care of creating the output variable with the right size.

Sign in to comment.

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices 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!