ANOVA of a cell array

3 次查看(过去 30 天)
car
car 2018-7-9
I'm looking to do a one-way ANOVA of a cell array, except when I use cellfun (as follows) I get an analysis of each individual cell as opposed to one analysis of all the cells (for example, if i have 8 cells, all of which have a different number of elements, I get 8 outputs when I want one output that compares the elements of all 8 cells).
p=cellfun(@anova1,master_maxt{1,1})
For reference, master_maxt is a 1x54 cell array, where {1,1} is a 1x8 cell array. Each of those 8 contains 57-120 elements. I am looking to do the same thing to all 54 of the arrays in master_maxt.
Thanks in advance for any help!

回答(1 个)

Vedant Shah
Vedant Shah 2025-2-20
Hi @car,
To perform a one-way ANOVA on all the data contained within the cells of a cell array and obtain a single output that compares all of them, you first need to combine the data from all the cells into a single vector. Subsequently, you can apply the anova1 function. For more information, please refer to the documentation using the following command in the MATLAB command line:
web(fullfile(docroot, "/stats/anova1.html"))
To execute the one-way ANOVA, following code can be used:
% Initialize variables to store combined data and group labels
combinedData = [];
groupLabels = [];
% Loop through each cell in master_maxt{1,1}
for i = 1:length(master_maxt{1,1})
% Extract data from each cell
data = master_maxt{1,1}{i};
% Append the data to the combinedData array
combinedData = [combinedData; data(:)];
% Create a group label array for this cell and append it to groupLabels
groupLabels = [groupLabels; i * ones(length(data), 1)];
end
% Perform one-way ANOVA
p = anova1(combinedData, groupLabels);
In this approach, the data from all cells is collected, and each data point is assigned a group label corresponding to its original cell. This process allows for a single output that compares all the cells as intended.

类别

Help CenterFile Exchange 中查找有关 Analysis of Variance and Covariance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by