How to divide Vectors of different length?

조회 수: 3 (최근 30일)
krishnamurthy
krishnamurthy 2013년 4월 9일
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
Yao Li
Yao Li 2013년 4월 9일
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.

댓글을 달려면 로그인하십시오.

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 4월 9일
편집: Azzi Abdelmalek 2013년 4월 9일
a=linspace(1,16,16);
b=linspace(1,4,4);
d=reshape(a,[],numel(b))
out=bsxfun(@rdivide,x,b)
c=out(:)'
  댓글 수: 1
Yao Li
Yao Li 2013년 4월 9일
x should be d ^_^
This works well only the length of a is an integral multiple of the length of b.

댓글을 달려면 로그인하십시오.


Andrei Bobrov
Andrei Bobrov 2013년 4월 9일
c = a./kron(b,[1 1 1 1]);

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by