Filter löschen
Filter löschen

mutiplying a role of number and seach or max and min value

3 Ansichten (letzte 30 Tage)
kevin
kevin am 18 Nov. 2011
let say a=[1:1:3] and b=[3:1:5]
and c = a*b
do i need to do anyting to make sure it multiply so it goes like 1*3 1*4 1*5 , 2*3 2*4 etc instead of 1*3 2*4 3*5?
and how do you find a and b when c is max or min?

Antworten (4)

Honglei Chen
Honglei Chen am 18 Nov. 2011
You can use kron to do what you want.
kron(a,b)
doc kron
As to finding out what a and b is, given the regular structure in the product, once you know the index for max and min in c, it should be fairly easy to find out what the corresponding index in a and b. Using your example, let's say the index for max in c is Nc, then the index in a (Na) and b (Nb) can be calculated like
Na = fix(Nc-1,3)+1
Nb = Nc-(Na-1)*3
HTH

Thomas
Thomas am 18 Nov. 2011
Kron is a good way to do it,
However you could code multiple for loops and work it.. I hope this was not a homework problem..
c=[];
for a=
for b=
c1=a*b;
c=[c,c1];
if c1==max(c)
maxab=[a,b];
end
end
end
max(c)
maxab
  1 Kommentar
Jan
Jan am 18 Nov. 2011
"close all; clear all" is useless here. See: http://www.mathworks.com/matlabcentral/answers/16484-good-programming-practice#answer_22301

Melden Sie sich an, um zu kommentieren.


Andrei Bobrov
Andrei Bobrov am 18 Nov. 2011
a=1:3;
b=3:5;
c = a(:)*b(:).';
[~, a2] = cellfun(@(x)x(c(:)),{@min,@max});
[iout,jout] = ind2sub(size(c),a2);
c_min = [a(iout(1)) b(jout(1))]
c_max = [a(iout(2)) b(jout(2))]
ADD 19:01MDT 27.11.2011
out = bsxfun(@rdivide,a.',b)
or (20:14MDT 27 Nov 2011)
out = a.'*(1./b)
[~, a3] = cellfun(@(x)x(out(:)),{@min,@max});
idx_a = rem(a3-1,numel(a))+1; % for min and max of a/b
idx_b = ceil(a3/numel(a));

Image Analyst
Image Analyst am 18 Nov. 2011
Here, run this code and I think you'll see what you're trying to figure out:
a=[1:1:3] % Row vector using your strange syntax.
b=[3:1:5] % Another row vector.
c1 = a' * b % Note transpose operator '
c2 = a .* b % Note dot
From your description, it sounds like you're wanting to make sure you get c1 and not c2. Results:
a =
1 2 3
b =
3 4 5
c1 =
3 4 5
6 8 10
9 12 15
c2 =
3 8 15
Now, for the max part:
% Find max of c1
cMax = c1 == max(c1(:))
% Find row(s) and columns(s) where c1 = cMax.
[rowsOfMax colsOfMax] = find(cMax)
% Extract out a and b where c == cMax.
aAtCMax = a(rowsOfMax)
bAtCMax = b(colsOfMax)
Do similar for the min of c1.
  8 Kommentare
kevin
kevin am 27 Nov. 2011
it didnt work, here is the code i used
a=[1:1:3]
b=[3:1:5]
bReciprocal =1./b
c=(a*bReciprocal)'
and i get
bReciprocal = 0.3333 0.2500 0.2000
??? Error using ==> mtimes
Inner matrix dimensions must agree.
is there any way to treat a and b as a range of number instead as a matrix?
kevin
kevin am 27 Nov. 2011
my actual question is more like a b and c is a number range from 1 to 10, d is range from 10 to 34)
and i try to f= (a/(b*c))*tan(d)

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by