How to shift values?

조회 수: 3 (최근 30일)
Eliana Scott
Eliana Scott 2020년 11월 11일
답변: Sameer 2025년 5월 9일
Can I get help on this? Its just supposed to be 3 statements so I put:
sampleReadings = [12, 85, 43];
sampleReadings(4) = -1;
ShiftValues = ????
I don't even think I can put sampleReadings(4) = -1; because it's not defined but I'm just not sure what to do.

답변 (1개)

Sameer
Sameer 2025년 5월 9일
The current function definition is incomplete, and you need to write statements that will:
  1. Move each element one position to the left.
  2. Set the last element to -1 after shifting.
You need to use array indexing to assign values to the appropriate positions in the array. If you are not sure how to do this, I recommend checking out the official MATLAB documentation
These resources should help you understand how to access and modify specific elements in an array. Once you are comfortable with that, you should be able to write the three required statements to shift the values as described in the problem.
If you want to learn more about MATLAB basics, including arrays and indexing, you should try MATLAB Onramp — a free, interactive tutorial provided by MathWorks.
Hope this helps!

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by