开发者

find out the maximum row from each 100 iteration in matlab

开发者 https://www.devze.com 2023-03-20 03:10 出处:网络
i have create a mat file: S = load abc.mat S = data1: [81x30 double] data2: [59x28 double] data3: [20x28 double]

i have create a mat file:

S = load abc.mat

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

after loading this mat file, then i use this mat file to run some code and the result display as below in the command window

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   开发者_StackOverflow社区 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

The fist column is from ball 30 to ball 100 (30:5:100), the 2nd column is the 100 iteration, then the 3rd, 4th, 5th and 6th is the result for A, B, C, D

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

i would like to plot a line graph which include max c in each index (ball)..where x-axis is t (ball 30 to 100) and y-axis is the variable c...may i know how to draw?

and also display out the row of maximum c on each index (ball) in a .txt file...

result: 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

Does anyone can help me plot the graph and get the def.txt? Thanks...


This is a job for 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])
0

精彩评论

暂无评论...
验证码 换一张
取 消