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
19 次查看(过去 30 天)
显示 更早的评论
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'});
[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(' ');
2 个评论
Cris LaPierre
2023-5-2
Please share your mat files. You can attach them to your post using the paperclip icon
采纳的回答
Cris LaPierre
2023-5-2
The issue is that X is a 2x108 but Group is 1x3. They must be the same length.
See this example: https://www.mathworks.com/help/stats/anova1.html#buos6wf-1
20 个评论
Cris LaPierre
2023-5-9
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File 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!