Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Find the minimum

Subject: Find the minimum

From: Diego Zegarra

Date: 16 Oct, 2008 16:34:02

Message: 1 of 5

Hey guys I need help with this. If I have an array which is,

MTT = cell(12:1)

and each cell of that array (e.g. MTT{1}) has a matrix of 120 x 120 and I want to find the minimum number out of the diagonal of each matrix and just get the minimum number out of all 12 cells how can I do that?

I am using the following,

[a b] = min(diag(MTT{idx}));

which gives me the minimum but it overrides every time. Should I create an array to save this minimum numbers? How do I get the minimum number out of that array then?

Thanks for your help and I hope I made myself clear.

Subject: Find the minimum

From: Walter Roberson

Date: 16 Oct, 2008 16:43:45

Message: 2 of 5

Diego Zegarra wrote:
> If I have an array which is,
>
> MTT = cell(12:1)
>
> and each cell of that array (e.g. MTT{1}) has a matrix of 120 x 120 and I want to find
> the minimum number out of the diagonal of each matrix and just get the minimum number
> out of all 12 cells how can I do that?

min(cellfun(@(a) min(diag(a)), MTT))

Subject: Find the minimum

From: Arvind Iyer

Date: 16 Oct, 2008 16:49:03

Message: 3 of 5

This isn't very compact code, but is this what you want?

MTT = cell(12:1);

%Generating random matrices...mth matrix of mean m and unit variance
for m = 1:12
    MTT{m} = m + randn(120);
end

matmins = zeros(1,length(MTT));
diagmins = zeros(1,length(MTT));
for n = 1:length(MTT);
    M = MTT{n};
    diagmins(n) = min(diag(M));
    matmins(n) = min(min(M));
end
%diagmins is an array of all diagonal minimums...matmins an array of
%complete matrix minimums


"Diego Zegarra" <diegozbb@gmail.com> wrote in message <gd7qdq$h2p$1@fred.mathworks.com>...
> Hey guys I need help with this. If I have an array which is,
>
> MTT = cell(12:1)
>
> and each cell of that array (e.g. MTT{1}) has a matrix of 120 x 120 and I want to find the minimum number out of the diagonal of each matrix and just get the minimum number out of all 12 cells how can I do that?
>
> I am using the following,
>
> [a b] = min(diag(MTT{idx}));
>
> which gives me the minimum but it overrides every time. Should I create an array to save this minimum numbers? How do I get the minimum number out of that array then?
>
> Thanks for your help and I hope I made myself clear.

Subject: Find the minimum

From: Diego Zegarra

Date: 16 Oct, 2008 16:53:02

Message: 4 of 5

Walter thanks for your answer. Yes that gives me the minimum value but how should I go about storing these to then be able to find the minimum out of all 12. I did not mention this before but I also need to know the position of that min value, meaning the column number.

Thanks

Subject: Find the minimum

From: Diego Zegarra

Date: 16 Oct, 2008 16:59:03

Message: 5 of 5

Hey Arvind thanks for your reply. Well I have the matrices already, I do not need to generate them. I need to save actually both the minimum number and the position(column) where it is.


> This isn't very compact code, but is this what you want?
>
> MTT = cell(12:1);
>
> %Generating random matrices...mth matrix of mean m and unit variance
> for m = 1:12
> MTT{m} = m + randn(120);
> end
>
> matmins = zeros(1,length(MTT));
> diagmins = zeros(1,length(MTT));
> for n = 1:length(MTT);
> M = MTT{n};
> diagmins(n) = min(diag(M));
> matmins(n) = min(min(M));
> end
> %diagmins is an array of all diagonal minimums...matmins an array of
> %complete matrix minimums

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us