How to divide Vectors of different length?

3 Ansichten (letzte 30 Tage)
krishnamurthy
krishnamurthy am 9 Apr. 2013
I have declared vectors 'a' and 'b'
Now the I want divide vector 'a' by vector 'b' and the result must store it in vector 'c'
The problem is vectors 'a' and 'b' are different lengths
But I managed by using the code given below;
Any one can try to assist this code to rewrite in a general format
a=linspace(1,16,16);
b=linspace(1,4,4);
c1 = a(1:4)./b(1);
c2 = a(5:8)./b(2);
c3 = a(9:12)./b(3);
c4 = a(13:16)./b(4);
c=[c1 c2 c3 c4];
c=[1,2,3,4,2.5,3,3.5,4,3,3.33,3.66,4,3.25,3.50,3.75,4;]
  1 Kommentar
Yao Li
Yao Li am 9 Apr. 2013
Is the length of a always an integral multiple of the length of b? It's important because we must first find out how many parts a is divided to.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 9 Apr. 2013
Bearbeitet: Azzi Abdelmalek am 9 Apr. 2013
a=linspace(1,16,16);
b=linspace(1,4,4);
d=reshape(a,[],numel(b))
out=bsxfun(@rdivide,x,b)
c=out(:)'
  1 Kommentar
Yao Li
Yao Li am 9 Apr. 2013
x should be d ^_^
This works well only the length of a is an integral multiple of the length of b.

Melden Sie sich an, um zu kommentieren.


Andrei Bobrov
Andrei Bobrov am 9 Apr. 2013
c = a./kron(b,[1 1 1 1]);

Kategorien

Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by