I have 189 sets of data, each has dimensions 30x27x159. I input all of them into a cell array using code as stated below. Now I want to find the mean of each set of data. How can i loop all of them and set their name accordingly?

1 visualización (últimos 30 días)
(data import)
clear all
close all
clc
files = dir('*.mat');
for i=1:length(files)
eval(['load ' files(i).name ' -ascii']);
end
(code to find mean)
mean(mean(data,1),2
temp=mean(mean(data,1,),2)
bp_5percmean_1=squeeze(temp)

Respuestas (1)

Srivardhan Gadila
Srivardhan Gadila el 31 de Oct. de 2020
From the above code I see that you have used the mean function twice, instead of that you can make use of the following syntax M = mean(A,vecdim). Refer to the explanation of vecdim.
In the below code I'm generating cell array of random data according to the dimensions mentioned in the question and looping it to calculate the mean:
data = arrayfun(@(x)rand([30 27 159]),1:189,'UniformOutput',false)';
meanData = {};
for i=1:189
% meanData{i,1} = mean(data{i},[1 2]);
meanData{i,1} = squeeze(mean(data{i},[1 2]));
end
Note that you may have to modify the above code according to your usage.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by