How to divide Vectors of different length?
    5 views (last 30 days)
  
       Show older comments
    
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 Comment
  Yao Li
      
 on 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.
Answers (2)
  Azzi Abdelmalek
      
      
 on 9 Apr 2013
        
      Edited: Azzi Abdelmalek
      
      
 on 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 Comment
  Yao Li
      
 on 9 Apr 2013
				x should be d ^_^
This works well only the length of a is an integral multiple of the length of b.
See Also
Categories
				Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


