필터 지우기
필터 지우기

Compensate the vector with the last entry

조회 수: 1 (최근 30일)
mingcheng nie
mingcheng nie 2023년 4월 25일
답변: Stephen23 2023년 4월 25일
I have a length L vector contains some numbers, I want to compensate this vector to length K, where K > L, with repeating the last entry of the vector. For example, the vector is [2 4 7 3], after compensate, it will be [2 4 7 3 3 3 3 3]. I hope there is an efficient way to do so because I actually have more than 10^4 vectors to compensate.
Thanks,
  댓글 수: 1
Stephen23
Stephen23 2023년 4월 25일
"I hope there is an efficient way to do so because I actually have more than 10^4 vectors to compensate."
Do you really have 1e4 separate vectors stored in the workspace? How did you get them all there?

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

답변 (1개)

Stephen23
Stephen23 2023년 4월 25일
V = [2,4,7,3];
K = 8;
V(end+1:K) = V(end)
V = 1×8
2 4 7 3 3 3 3 3

카테고리

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

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by