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:
doubts in matlab

Subject: doubts in matlab

From: Shobana

Date: 17 Feb, 2013 11:21:06

Message: 1 of 4

Hai...
     I am tried to find minimum value of particular columns and rows separately but i am getting wrong answers.
  for example a = [1 2 3 ;
                          6 5 4;
                          8 1 7]
          [x y] = min(a(2:end,2))

instead of getting x= 3 y =2 i am getting some other value.how to write correct code for this concept.
Thanks in advance

Subject: doubts in matlab

From: dpb

Date: 17 Feb, 2013 14:28:52

Message: 2 of 4

On 2/17/2013 5:21 AM, Shobana wrote:
> Hai...
> I am tried to find minimum value of particular columns and rows
> separately but i am getting wrong answers.
> for example a = [1 2 3 ;
> 6 5 4;
> 8 1 7]
> [x y] = min(a(2:end,2))
>
> instead of getting x= 3 y =2 i am getting some other value.how to write
> correct code for this concept.
> Thanks in advance

a(2:end,2) ==> [5;1] % 2nd to last rows, 2nd column

so you should find [x,y] == [1,2]

Not sure which you were really after that would return your expected
results otomh I don't see one.

If you're trying to write a subset of the array and then work min() on
the 2nd dimension, the ',2' is misplaced above (and you're missing the
2nd dimension for the subscript expression if you simply move it.

Try something like

[x ix] = min(a(2:end,:),2)

and see if you can get where you're going from there.

--

Subject: doubts in matlab

From: Shobana

Date: 18 Feb, 2013 03:57:06

Message: 3 of 4

dpb <none@non.net> wrote in message <kfqpf8$mhc$1@speranza.aioe.org>...
> On 2/17/2013 5:21 AM, Shobana wrote:
> > Hai...
> > I am tried to find minimum value of particular columns and rows
> > separately but i am getting wrong answers.
> > for example a = [1 2 3 ;
> > 6 5 4;
> > 8 1 7]
> > [x y] = min(a(2:end,2))
> >
> > instead of getting x= 3 y =2 i am getting some other value.how to write
> > correct code for this concept.
> > Thanks in advance
>
> a(2:end,2) ==> [5;1] % 2nd to last rows, 2nd column
>
> so you should find [x,y] == [1,2]
>
> Not sure which you were really after that would return your expected
> results otomh I don't see one.
> sorry its not working.its showing me an error
> If you're trying to write a subset of the array and then work min() on
> the 2nd dimension, the ',2' is misplaced above (and you're missing the
> 2nd dimension for the subscript expression if you simply move it.
>
> Try something like
>
> [x ix] = min(a(2:end,:),2)
>
> and see if you can get where you're going from there.
>
> --

Subject: doubts in matlab

From: dpb

Date: 18 Feb, 2013 05:00:52

Message: 4 of 4

On 2/17/2013 9:57 PM, Shobana wrote:
> dpb <none@non.net> wrote in message <kfqpf8$mhc$1@speranza.aioe.org>...
>> On 2/17/2013 5:21 AM, Shobana wrote:
>> > Hai...
>> > I am tried to find minimum value of particular columns and rows
>> > separately but i am getting wrong answers.
>> > for example a = [1 2 3 ;
>> > 6 5 4;
>> > 8 1 7]
>> > [x y] = min(a(2:end,2))
>> >
>> > instead of getting x= 3 y =2 i am getting some other value.how to write
>> > correct code for this concept.
>> > Thanks in advance
>>
>> a(2:end,2) ==> [5;1] % 2nd to last rows, 2nd column
>>
>> so you should find [x,y] == [1,2]
>>
>> Not sure which you were really after that would return your expected
>> results otomh I don't see one.
>> sorry its not working.its showing me an error

Well, w/o seeing what you did and the error, can't comment...the above
is commentary, not code. The subset of a given by (2:end,2) is a column
vector containing 5,1. So, the min() of that vector is 1 and the second
location.

>> If you're trying to write a subset of the array and then work min() on
>> the 2nd dimension, the ',2' is misplaced above (and you're missing the
>> 2nd dimension for the subscript expression if you simply move it.
>>
>> Try something like
>>
>> [x ix] = min(a(2:end,:),2)
...

Oh, sorry...for the dimension optional argument, need an empty
comparison field--the above compares the subarray to the constant 2, not
what I was intending...

[x ix] = min(a(2:end,:),[],2);

doc min

--

Tags for this Thread

No tags are associated with 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