error: X and GROUP must have the same length.but the lengths are the same. This must be a malfunctin how can i fix please help

38 visualizaciones (últimos 30 días)
i have 6 feature mats files, 3 structs per mat file giving 18 struct total I want perform anova test per 6 struct so i ahve grouped but error:X and GROUP must have the same length.
Error in anova_cntrldiet (line 38)
[p_profileCounts, tbl_profileCounts, stats_profileCounts] = anova1([profileCounts1, profileCounts2, profileCounts3], {'Mouse1', 'Mouse2', 'Mouse3'});
please assist in fixing error so i can perform anova test thank you.
clear all;
% Load the features:
feature1 = load('feature1.mat');
feature2 = load('feature2.mat');
feature3 = load('feature3.mat');
feature4 = load('feature4.mat');
feature5 = load('feature5.mat');
feature6 = load('feature6.mat');
% Combine all of the structs into a single feature for each mouse
mouse1 = struct('lobule1', feature1.features, 'lobule2', feature2.features);
mouse2 = struct('lobule1', feature3.features, 'lobule2', feature4.features);
mouse3 = struct('lobule1', feature5.features, 'lobule2', feature6.features);
% Extract the desired fields from each mouse
profileCounts1 = [mouse1.lobule1.profileCounts; mouse1.lobule2.profileCounts];
totalArea1 = [mouse1.lobule1.totalArea; mouse1.lobule2.totalArea];
avgSize1 = [mouse1.lobule1.avgSize; mouse1.lobule2.avgSize];
AvgCircularityy1 = [mouse1.lobule1.AvgCircularityy; mouse1.lobule2.AvgCircularityy];
AvgFeret1 = [mouse1.lobule1.AvgFeret; mouse1.lobule2.AvgFeret];
AvgMinFeret1 = [mouse1.lobule1.AvgMinFeret; mouse1.lobule2.AvgMinFeret];
profileCounts2 = [mouse2.lobule1.profileCounts; mouse2.lobule2.profileCounts];
totalArea2 = [mouse2.lobule1.totalArea; mouse2.lobule2.totalArea];
avgSize2 = [mouse2.lobule1.avgSize; mouse2.lobule2.avgSize];
AvgCircularityy2 = [mouse2.lobule1.AvgCircularityy; mouse2.lobule2.AvgCircularityy];
AvgFeret2 = [mouse2.lobule1.AvgFeret; mouse2.lobule2.AvgFeret];
AvgMinFeret2 = [mouse2.lobule1.AvgMinFeret; mouse2.lobule2.AvgMinFeret];
profileCounts3 = [mouse3.lobule1.profileCounts; mouse3.lobule2.profileCounts];
totalArea3 = [mouse3.lobule1.totalArea; mouse3.lobule2.totalArea];
avgSize3 = [mouse3.lobule1.avgSize; mouse3.lobule2.avgSize];
AvgCircularityy3 = [mouse3.lobule1.AvgCircularityy; mouse3.lobule2.AvgCircularityy];
AvgFeret3 = [mouse3.lobule1.AvgFeret; mouse3.lobule2.AvgFeret];
AvgMinFeret3 = [mouse3.lobule1.AvgMinFeret; mouse3.lobule2.AvgMinFeret];
[p_profileCounts, tbl_profileCounts, stats_profileCounts] = anova1([profileCounts1, profileCounts2, profileCounts3], {'Mouse1', 'Mouse2', 'Mouse3'});
Error using anova1
X and GROUP must have the same length.
[p_totalArea, tbl_totalArea, stats_totalArea] = anova1([totalArea1, totalArea2, totalArea3], {'Mouse1', 'Mouse2', 'Mouse3'});
[p_avgSize, tbl_avgSize, stats_avgSize] = anova1([avgSize1, avgSize2, avgSize3], {'Mouse1', 'Mouse2', 'Mouse3'});
[p_AvgCircularityy, tbl_AvgCircularityy, stats_AvgCircularityy] = anova1([AvgCircularityy1, AvgCircularityy2, AvgCircularityy3], {'Mouse1', 'Mouse2', 'Mouse3'});
[p_AvgFeret, tbl_AvgFeret, stats_AvgFeret] = anova1([AvgFeret1, AvgFeret2, AvgFeret3], {'Mouse1', 'Mouse2', 'Mouse3'});
[p_AvgMinFeret, tbl_AvgMinFeret, stats_AvgMinFeret] = anova1([AvgMinFeret1, AvgMinFeret2, AvgMinFeret3], {'Mouse1', 'Mouse2', 'Mouse3'});
% Perform pairwise comparisons between each pair of mice for each feature
[pairwise_profileCounts, tbl_pairwise_profileCounts, stats_pairwise_profileCounts] = ...
anova2([profileCounts1', profileCounts2', profileCounts3'], 1, 'off');
[pairwise_totalArea, tbl_pairwise_totalArea, stats_pairwise_totalArea] = ...
anova2([totalArea1', totalArea2', totalArea3'], 1, 'off');
[pairwise_avgSize, tbl_pairwise_avgSize, stats_pairwise_avgSize] = ...
anova2([avgSize1', avgSize2', avgSize3'], 1, 'off');
[pairwise_AvgCircularityy, tbl_pairwise_AvgCircularityy, stats_pairwise_AvgCircularityy] = ...
anova2([AvgCircularityy1', AvgCircularityy2', AvgCircularityy3'], 1, 'off');
[pairwise_AvgFeret, tbl_pairwise_AvgFeret, stats_pairwise_AvgFeret] = ...
anova2([AvgFeret1', AvgFeret2', AvgFeret3'], 1, 'off');
[pairwise_AvgMinFeret, tbl_pairwise_AvgMinFeret, stats_pairwise_AvgMinFeret] = ...
anova2([AvgMinFeret1', AvgMinFeret2', AvgMinFeret3'], 1, 'off');
% Display the results
disp('Profile Counts:');
disp(tbl_profileCounts);
disp(pairwise_profileCounts);
disp(' ');
disp('Total Area:');
disp(tbl_totalArea);
disp(pairwise_totalArea);
disp(' ');
disp('Average Size:');
disp(tbl_avgSize);
disp(pairwise_avgSize);
disp(' ');
disp('Average Circularity:');
disp(tbl_AvgCircularityy);
disp(pairwise_AvgCircularityy);
disp(' ');
disp('Average Feret:');
disp(tbl_AvgFeret);
disp(pairwise_AvgFeret);
disp(' ');
disp('Average Minimum Feret:');
disp(tbl_AvgMinFeret);
disp(pairwise_AvgMinFeret);
disp(' ');

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 2 de Mayo de 2023
The issue is that X is a 2x108 but Group is 1x3. They must be the same length.
  20 comentarios
Cris LaPierre
Cris LaPierre el 9 de Mayo de 2023
That sort of comparison does not make sense to me. ANOVA is the analysis of variance. You only can have variance if you have more than one element in your group.
My code takes all the values for m1 and puts them in one column, and then takes all the values from m2 and puts them in a second column, and all values from m3 into the 3rd column (72x3), and then compares samples from m1 to the samples from m2 to the samples from m3 and tests if they are from the same population.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by