From: Alan on
Hi,
Anybody can help me with the following question: Say now I've got a 1 by 5 matrix A {a1,a2,a3,a4,a5}, and 1 by 5 matrix B {b1,b2,b3,b4,b5} and a 1 by 5 matrix C {c1,c2,c3,c4,c5}. I want to get the maximum quotient of {ai/bi} and AT THE SAME TIME return ai, bi, and ci (ci is a vector corresponding to ai and bi). How can I do it in Matlab? Using indexing?

Many thanks.
Alan
From: Walter Roberson on
Alan wrote:

> Anybody can help me with the following question: Say now I've got a 1 by
> 5 matrix A {a1,a2,a3,a4,a5}, and 1 by 5 matrix B {b1,b2,b3,b4,b5} and a
> 1 by 5 matrix C {c1,c2,c3,c4,c5}. I want to get the maximum quotient of
> {ai/bi} and AT THE SAME TIME return ai, bi, and ci (ci is a vector
> corresponding to ai and bi). How can I do it in Matlab? Using indexing?

No, you cannot do that. You need at least two steps:

[maxval, maxidx] = max( horzcat(A{:}) ./ horzcat(B{:}) );
vals = [a{maxidx}, b{maxidx}, c{maxidx}];

This presumes that when you wrote {a1,a2,a3,a4,a5} that you really did mean a
cell array rather than a numeric array, and presumes that each cell of the
array happens to consist of exactly 1 numeric value.

If your arrays are numeric then

[maxval, maxidx] = max( A ./ B );
vals = [a(maxidx), b(maxidx), c(maxidx)];
 | 
Pages: 1
Prev: file browser inside the GUI
Next: imrotate