Matlab: Average 2nd column when 1st column has same number and Minimum value in each row

min(x,[],2)

[m n] = size(A);
As = sortrows(A,1);
j = [0; find(diff([As(:,1); Inf]))]+1;
B = cumsum([zeros(1,n-1); As(:,2:end)]);
B = B(j,:);
B = diff(B,1,1);
n = diff(j);
B = bsxfun(@rdivide, B, n);
A1 = As(j(1:end-1));
B = [A1 B];

Link http://www.mathworks.com/matlabcentral/newsreader/view_thread/304172

Run Matlab in Tsubame

t2sub -l walltime=24:00:00 -W group_list=t2gBANgroup -q V -l select=8:ncpus=8:mpiprocs=8:mem=20gb -l place=scatter runMatlab.sh

Split matrix into small matricess

A = your_matrix [300,25]
Mcell = mat2cell(A,repmat(30,10,1),25)

Thoi gian tinh toan trong Matlab

% 計算所要時間の表示
startT = clock();
startCpuT = cputime;
%
% 自分の計算
%
ntime=cputime-startCpuT;
nhour = floor(ntime/60/60);
nmin = floor((ntime-nhour*3600)/60);
nsec = ntime-nhour*3600-nmin*60;
disp(sprintf(‘%s%s’, ‘開始時間:’,datestr(startT,31)));
disp(sprintf(‘%s%s’, ‘終了時間:’,datestr(clock,31)));
disp(sprintf(‘%s%d%s%02d%s%04.1f%s’, ‘計算所要時間:’,nhour,’時間’,nmin,’分’,nsec,’秒’));

Link: http://sach1o.blog80.fc2.com/blog-entry-26.html

MATLAB: find the maximum in a matrix

Link: http://nw360.blogspot.com/2006/12/matlab-find-maximum-in-matrix.html

Suppose we have a matrix a,
a =

81 91 27 96 95
90 63 54 15 48
12 9 95 97 80

and now we want to locate the maximum value 97. There are several approaches.

Use max only.
>> [row_val row_ind] =max(a, [], 1)

row_val =

90 91 95 97 95

row_ind =

2 1 3 3 1

>> [col_val col_ind] =max(row_val)

col_val =

97

col_ind =

4

The maximum value is at [row_ind(col_ind), col_ind]

Use find.
>> [r c] =find(a==max(a(:)))

r =

3

c =

4

Use single index.
>> [s_v s_i] =max(a(:))

s_v =

97

s_i =

12

>> [r c] =ind2sub(size(a), s_i)

r =

3

c =

4

*******************************************

Usually, to find the maximum value of a matirx, the following command is used:

max(a(:)) where a is a 2D matrix

The problem is that if the matrix size is too big, you may get yourself involved in a problem that is ??? Matrix is too large to convert to linear index. This is caused by a(:).

Try to use max(max(a)) instead.

Follow

Get every new post delivered to your Inbox.