solving simple equations in matlab

1 Ansicht (letzte 30 Tage)
Richard
Richard am 18 Dez. 2012
I have 2 variables:
d1 = 1:5;
d2 = 6:10;
I would like to calculate 'dat', which is given by:
dat = d1./(10.*d2);
However, the following returns a vector (as expected), how would I write this so that matlab returns a matrix i.e. the value for dat when d1 is 1:5 when d2 is 6 and then when d2 is 7, ultimately returning a 5x5 matrix. Is the only method of completing this through a loop.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 19 Dez. 2012
Bearbeitet: Andrei Bobrov am 19 Dez. 2012
dat = d1.'*(.1./d2);

Weitere Antworten (2)

Walter Roberson
Walter Roberson am 18 Dez. 2012
dat = bsxfun(@rdivide, d1.', d2) ./ 10;

Babak
Babak am 18 Dez. 2012
Bearbeitet: Babak am 18 Dez. 2012
d1 = 1:5;
d2 = 6:10;
for j=1:5
dat(j,:) = d1./(10.*d2(j));
end
dat

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by