matlab 方差分析代码
时间: 2023-08-23 15:10:09 浏览: 83
Sure! Here's an example code snippet for performing a one-way analysis of variance (ANOVA) in MATLAB:
```matlab
% Sample data for three groups
group1 = [1,2,3,4,5];
group2 = [2,4,6,8,10];
group3 = [3,6,9,12,15];
% Combine the data into a single matrix
data = [group1', group2', group3'];
% Perform one-way ANOVA
[p_value, tbl, stats] = anova1(data);
% Display the results
disp('One-way ANOVA results:');
disp(tbl);
disp('Post hoc multiple comparison:');
multcompare(stats);
```
In this example, we have three groups represented by `group1`, `group2`, and `group3`. We combine the data into a single matrix `data` and then use the `anova1` function to perform the ANOVA. The function returns the p-value, ANOVA table (`tbl`), and additional statistics (`stats`). Finally, we display the ANOVA results and perform post hoc multiple comparisons using the `multcompare` function.
You can modify this code according to your specific data and requirements.