필터 지우기
필터 지우기

Convert a vector to vector sequentially?

조회 수: 1 (최근 30일)
Nguyen Trong Nhan
Nguyen Trong Nhan 2020년 1월 3일
답변: Walter Roberson 2020년 1월 3일
I have 2 vector: init = [1 2 3 4], final =[5 6 7 8]. I would like to genertate all the vector like the following:
[1 2 3 4] [5 2 3 4] [5 6 3 4] [5 6 7 4] [5 6 7 8]. Is there anyway to do this fast using some special function available in matlab?

채택된 답변

Walter Roberson
Walter Roberson 2020년 1월 3일
%assuming init and final are the same size!!
init = [1 2 3 4];
final =[5 6 7 8];
output = repmat(init(:), 1, length(init));
toutput = repmat(final(:), 1, length(init));
mask = triu(true(size(output)),1);
output(mask) = toutput(mask);
And now the outputs are down the columns. If you really want vectors,
num2cell(output,1)

추가 답변 (1개)

Stephen23
Stephen23 2020년 1월 3일
>> init = [1 2 3 4]
>> final = [5 6 7 8]
>> X = triu(ones(5,4));
>> M = init.*X + final.*~X
M =
1 2 3 4
5 2 3 4
5 6 3 4
5 6 7 4
5 6 7 8

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by