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 次查看(过去 30 天)
显示 更早的评论
(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)
0 个评论
回答(1 个)
Srivardhan Gadila
2020-10-31
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!