Effacer les filtres
Effacer les filtres

Cell arrays inside a structure array - how to access and perform operations?

10 vues (au cours des 30 derniers jours)
MDias
MDias le 30 Jan 2021
Commenté : MDias le 1 Fév 2021
Hi,
I have a struct with a number of different fields. Some of these fields have two columns of cell arrays. Each cell array contains differently sized columns:
results.x{1,1} % has size 47x1
results.x{1,2} % has size 36x1
I need to:
1) Compute the mean of each cell.
2) Remove empty cells that might be found
3) Compute the mean of each column of cell arrays inside all fileds.
Not sure if I managed to clearly explain what I'm after. I've added a simplified exmaple file for clarity.
Any suggestion on how to approach this problem?

Réponse acceptée

David Hill
David Hill le 30 Jan 2021
I did not put x and t back into a struct.
a=find(ismember(isnan(results.timestamps),[1 1],'rows'),1)-1;%delete rows after
x=results.x(1:a,:);
t=results.timestamps(1:a,:);%does not seem you want to do anything with the timestamps
colmean=[mean(cell2mat(x(:,1))),mean(cell2mat(x(:,2)))];
cellmean=zeros(a,2);
for k=1:a
cellmean(k,1)=mean(x{k,1});
cellmean(k,2)=mean(x{k,2});
end
  2 commentaires
MDias
MDias le 31 Jan 2021
Thanks David! I'll try this out.
MDias
MDias le 1 Fév 2021
Worked perfectly!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by