How to extract specific elements from a struct variable?

조회 수: 5 (최근 30일)
Arti
Arti 2023년 9월 4일
댓글: Voss 2023년 9월 4일
I'm using a piece of code wherein the output is saved as a "struct" variable as in the screenshot below:
Within this, the traces variable is arranged as shown below (looks like a cell array):
Now I need to select values based on the first column, i.e., anything over 5x11 (the first element has to be 5 or greater). Plus, each of these "nx11 table" itself is arranged like so:
And eventually I just need to get the "row" and "col" columns from the tables which have (5+) x 11elements (that's the end goal). I got the code from somewhere to process my data and thus, don't know how to modify it to give output in a different way. But if someone could help me out, even partially, with these steps that would be great? I've attached the output along. Thanks!

채택된 답변

Voss
Voss 2023년 9월 4일
load trackResults2.mat
% idx is a logical vector, with one element for each row of trackRes.traces,
% which says whether the table in column 1 of that row of trackRes.traces
% has at least 5 rows:
idx = cellfun(@(x)size(x,1)>=5,trackRes.traces(:,1));
% from each of those tables (i.e., trackRes.traces(idx,1)), get the row and
% col columns:
result = cellfun(@(x)[x.row x.col],trackRes.traces(idx,1),'UniformOutput',false)
ans = 105×1 cell array
{20×2 double} { 5×2 double} { 7×2 double} {23×2 double} {18×2 double} {23×2 double} { 6×2 double} { 6×2 double} { 6×2 double} { 8×2 double} { 8×2 double} { 5×2 double} { 9×2 double} {14×2 double} { 8×2 double} {15×2 double}

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by