solving simple equations in matlab

3 次查看(过去 30 天)
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.

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-12-19
编辑:Andrei Bobrov 2012-12-19
dat = d1.'*(.1./d2);

更多回答(2 个)

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

Babak
Babak 2012-12-18
编辑:Babak 2012-12-18
d1 = 1:5;
d2 = 6:10;
for j=1:5
dat(j,:) = d1./(10.*d2(j));
end
dat

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by