필터 지우기
필터 지우기

Is there a built-in function to push my vector

조회 수: 1 (최근 30일)
Ali Almakhmari
Ali Almakhmari 2023년 4월 7일
답변: the cyclist 2023년 4월 7일
So lets say I have a vector that is 1 by 7 elements. I am trying to find a built-in function or write one where it can push the vector. Now, by push, I mean take the last element of the vector and move it to be the first element in the vector, and then push all the other elements to the right. For example:
My vector is: [1, 1, 0, 2, 3, 5, -1]. After the push command, it will become: [-1, 1, 1, 0, 2, 3, 5], if I push it again: [5, -1, 1, 1, 0, 2 ,3]. And so on. I wrote a system of for loops to do this but its soooo inefficient considering that I have to do this process so many times.

채택된 답변

the cyclist
the cyclist 2023년 4월 7일
v = [1, 1, 0, 2, 3, 5, -1];
circshift(v,1)
ans = 1×7
-1 1 1 0 2 3 5

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by