From: Ulrik Nash on
"us " <us(a)neurol.unizh.ch> wrote in message <i1mqt5$obr$1(a)fred.mathworks.com>...
> "Ulrik Nash" <uwn(a)sam.sdu.dk> wrote in message <i1mq8h$e13$1(a)fred.mathworks.com>...
> > "Ulrik Nash" <uwn(a)sam.sdu.dk> wrote in message <i1mprd$hqs$1(a)fred.mathworks.com>...
> > > "us " <us(a)neurol.unizh.ch> wrote in message <i1mpg4$p36$1(a)fred.mathworks.com>...
> > > > "Ulrik Nash" <uwn(a)sam.sdu.dk> wrote in message <i1mov9$m1f$1(a)fred.mathworks.com>...
> > > > > Hi Everyone,
> > > > >
> > > > > I it possible to reduce the following to a single line?
> > > > >
> > > > > A = max([firm_profit(:,t),firm_price(:,t)])
> > > > > B = A(1,1)
> > > > >
> > > > > Kind regards,
> > > > >
> > > > > Ulrik.
> > > >
> > > > yes, of course...
> > > >
> > > > A=max([firm_profit(:,t),firm_price(:,t)]);B=A(1,1);
> > > >
> > > > us
> > >
> > > That is neat! Thanks us! :-)
> >
> >
> > Maybe I was a little fast there. Is it not possible to achieve the result with only one equation?
>
> well... the first reply was a ...JOKE..., of course...
>
> one of the solutions
>
> [a,b]=deal(max(-1:2))
> % a = 2
> % b = 2
>
> us

Haha, and I fell, no, jumped right in :-) Be nice to beginners! ;-) anyway, dare I say thanks this time?
From: Jan Simon on
Dear Ulrik,

> I it possible to reduce the following to a single line?
> A = max([firm_profit(:,t),firm_price(:,t)])
> B = A(1,1)

I do not see a benefit in redusing the number of lines.
If you want to have the variables A and B, it is not possible. But if you want just B to be the maximum of the first column, you can omit the 2nd column:
B = max(firm_profit(:, t));
Are you sure, that this is what you want to get?

Jan
From: Ulrik Nash on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i1mrus$1k6$1(a)fred.mathworks.com>...
> Dear Ulrik,
>
> > I it possible to reduce the following to a single line?
> > A = max([firm_profit(:,t),firm_price(:,t)])
> > B = A(1,1)
>
> I do not see a benefit in redusing the number of lines.
> If you want to have the variables A and B, it is not possible. But if you want just B to be the maximum of the first column, you can omit the 2nd column:
> B = max(firm_profit(:, t));
> Are you sure, that this is what you want to get?
>
> Jan

Hi Jan,

What I want to achieve is an isolation of the price at which profit is greatest. I was hoping this could be done in a single line, to get a single value.

Ulrik.
From: dpb on
Ulrik Nash wrote:
> "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message
> <i1mrus$1k6$1(a)fred.mathworks.com>...
>> Dear Ulrik,
>>
>> > I it possible to reduce the following to a single line?
>> > A = max([firm_profit(:,t),firm_price(:,t)])
>> > B = A(1,1)
>>
>> I do not see a benefit in redusing the number of lines.
>> If you want to have the variables A and B, it is not possible. But if
>> you want just B to be the maximum of the first column, you can omit
>> the 2nd column:
>> B = max(firm_profit(:, t));
>> Are you sure, that this is what you want to get?
>>
>> Jan
>
> Hi Jan,
> What I want to achieve is an isolation of the price at which profit is
> greatest. I was hoping this could be done in a single line, to get a
> single value.
....

Look at the optional return values of max()

doc max

Still need two steps afaict. Otherwise, the locations of the two max
values aren't correlated. You've returned each of the maximum of price
_and_ maximum profit, not necessarily the price for max profit as is
(unless, of course, there's nothing going on in the data other than a
higher price produces a higher profit in which case there's nothing to
learn from the data anyway as it's in/from a region of totally elastic
price/volume relationship).

--
From: Jan Simon on
Dear Ulrik,

> > > A = max([firm_profit(:,t),firm_price(:,t)])
> > > B = A(1,1)

> What I want to achieve is an isolation of the price at which profit is greatest. I was hoping this could be done in a single line, to get a single value.

Aha (sorry, I cannot translate this). This is something different. Did you try to run the code you've posted??

Here is your desired one-liner:
B = price(profit(:, t) == max(profit(:, t)), t);
I've omitted the redundant "firm_".
Of course this is less efficient than using the 2nd output of the MAX command to get the index of the greatest element:
[dum, index] = max(profit(:, t));
B = price(index, t);
Anyway, you have to care for multiple or empty max values (if "profit" is NaN...).

Kind regards, Jan