【问题标题】:find out the maximum row from each 100 iteration in matlab从matlab中的每100次迭代中找出最大行
【发布时间】:2011-07-15 09:46:36
【问题描述】:

我已经创建了一个 mat 文件:

S = load abc.mat

S = data1: [81x30 double]
    data2: [59x28 double]
    data3: [20x28 double]

加载这个 mat 文件后,我使用这个 mat 文件运行一些代码,结果在命令窗口中显示如下

disp([Ball Trial A B C D])

30.0000    1.0000    0.4498    0.3652    0.4601    0.3777

30.0000    2.0000    0.5745    0.5006    0.5671    0.4940

...

30.0000   99.0000    0.5209    0.4420    0.5112    0.4311

30.0000  100.0000    0.4078    0.4142    0.3974    0.4060

35.0000    1.0000    0.4303    0.3563    0.4083    0.3356

35.0000    2.0000    0.5239    0.4469    0.5174    0.4396

...

35.0000   99.0000    0.6009    0.5442    0.5985    0.5410

35.0000  100.0000    0.5327    0.4756    0.5037    0.4503

...

100.0000   99.0000    0.3015    0.3273    0.3027    0.3287

100.0000  100.0000    0.4416    0.3960    0.4533    0.4088

第一列是从ball 30到ball 100(30:5:100),第二列是100次迭代,那么第3、4、5、6是A、B、C、D的结果

[c t] = max(max(C.'));% variable c is the max of C in each ball (index) t.

我想绘制一个折线图,其中包括每个索引中的最大 c(球)..其中 x 轴是 t(球 30 到 100),y 轴是变量 c...我可以知道如何画画?

并在 .txt 文件中显示每个索引(球)上最大 c 的行...

结果:def.txt

30.000 23.000 0.23 0.45 0.76 0.32

35.000 19.000 0.43 0.67 0.23 0.54

...

100.000 43.000 0.54 0.11 0.54 0.99

有人可以帮我绘制图表并获取 def.txt 吗?谢谢...

【问题讨论】:

    标签: matlab


    【解决方案1】:

    这是ACCUMARRAY 的工作。

    %# data is the content of abc.mat
    load('abc.mat')
    
    %# find x, corresponding indices into y
    [x,~,yIdx] = unique(data(:,1));
    
    %# in each column, collect the maximum for each yIdx
    y = zeros(length(x),4);
    for col=1:4
        y(:,col) = accumarray(yIdx,data(:,col+2),[],@max);
    end
    
    %# plot
    ph=plot(x,y);
    set(ph,{'DisplayName'},{'A';'B';'C';'D'})
    legend()
    
    %# save result to file
    dlmwrite('def.txt', [x y])
    

    【讨论】:

    • ???索引超出矩阵维度。 ==> 在 10 处测试时出错 y(:,col) = accumarray(yIdx,S(:,col+2),[],@max);
    • @noob: 代替S 使用data where data = [Ball Trial A B C D];
    猜你喜欢
    • 1970-01-01
    • 2023-03-05
    • 2021-11-20
    • 2021-05-22
    • 1970-01-01
    • 2014-02-16
    • 1970-01-01
    • 2019-07-04
    • 1970-01-01
    相关资源
    最近更新 更多