gpt4 book ai didi

matlab - 对矩阵中特定列的数据进行分组和绘图

转载 作者:行者123 更新时间:2023-12-02 07:16:26 25 4
gpt4 key购买 nike

在矩阵中解析和分组数据后,我尝试在矩阵中散点绘制数据,但出现了一些错误。我解析和分组的数据矩阵如下所示:

a = [1.05 2.1 3.4 1; 1.06 2.2 3.6 1; 2.04 2.3 3.8 2; 2.15 2.2 4.0 2; 1.37 2.3 3.7 1;3.12 2.1 4.1 3;3.02 2.2 4.2 3;3.42 2.3 4.5 3;3.24 2.4 4.8 3]

a =

1.0500 2.1000 3.4000 1.0000
1.0600 2.2000 3.6000 1.0000
2.0400 2.3000 3.8000 2.0000
2.1500 2.2000 4.0000 2.0000
1.3700 2.3000 3.7000 1.0000
3.1200 2.1000 4.1000 3.0000
3.0200 2.2000 4.2000 3.0000
3.4200 2.3000 4.5000 3.0000
3.2400 2.4000 4.8000 3.0000

我对 a(:,1) 值进行四舍五入并将其放入 a(:,4) 中。

所需的绘图应如下所示(我在 Excel 中绘制它们):

enter image description here

基本上我需要根据 a(:,4) 中的值对数据进行分组。

我编写了以下代码:

splitapply(@(x,y)plot(x,y),a(:,2),a(:,3),findgroups(a(:,4)))

情节如下:

enter image description here

如何绘制如第一张图所示的数据(在 Excel 中绘制)?

最佳答案

你忘记坚持。添加一些更好的绘图选项:

hold on
% same thing you have but with markers!
splitapply(@(x,y)plot(x,y,'marker','.','markersize',20),a(:,2),a(:,3),findgroups(a(:,4)))
axis([2.05 2.45 0 6]) %same as excel
grid on

enter image description here

关于matlab - 对矩阵中特定列的数据进行分组和绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55144888/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com