How to divide Vectors of different length?

3 vues (au cours des 30 derniers jours)
krishnamurthy
krishnamurthy le 9 Avr 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 commentaire
Yao Li
Yao Li le 9 Avr 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.

Connectez-vous pour commenter.

Réponses (2)

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

Connectez-vous pour commenter.


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

Catégories

En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by