필터 지우기
필터 지우기

how to multiply simplest way this two vectors ?

조회 수: 2 (최근 30일)
x y
x y 2014년 12월 3일
댓글: Stephen23 2014년 12월 3일
I have to multiply this xi and y this way:
xi = [98 99 100 101 102 103]; y = [2 4 6 4 3 1]; x = [ 98*ones(1,2), 99*ones(1,4), 100*ones(1,6), 101*ones(1,4),... 102*ones(1,3), 103*ones(1,1) ]
it is possible to somthing this to make.... x = xi.*( ones(1,y(1:end)) ) % this is not working

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 3일
편집: Azzi Abdelmalek 2014년 12월 3일
xi = [98 99 100 101 102 103];
y = [2 4 6 4 3 1];
x=cell2mat(arrayfun(@(a,b) a*ones(1,b),xi,y,'un',0))
%or you can do it just by using a for loop

추가 답변 (2개)

Guillaume
Guillaume 2014년 12월 3일
편집: Guillaume 2014년 12월 3일
This is not a multiplication.
One of many ways to do what you want:
xi = [98 99 100 101 102 103];
y = [2 4 6 4 3 1];
x = cell2mat(arrayfun(@(v, r) repmat(v, 1, r), xi, y, 'UniformOutput', false))

Andrei Bobrov
Andrei Bobrov 2014년 12월 3일
a = accumarray(cumsum([1; y(:)]),1);
x = xi(cumsum(a(1:end-1)));

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by