mutiplying a role of number and seach or max and min value
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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?
0 Commenti
Risposte (4)
Honglei Chen
il 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
0 Commenti
Thomas
il 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 Commento
Jan
il 18 Nov 2011
"close all; clear all" is useless here. See: http://www.mathworks.com/matlabcentral/answers/16484-good-programming-practice#answer_22301
Andrei Bobrov
il 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));
0 Commenti
Image Analyst
il 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 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!