Im trying to fix a code in my home work, the directions state to Write a *single* statement that shifts row array attendanceValues one position to the left. The rightmost element in shiftedValues also keeps its value. any thoughts

3 ビュー (過去 30 日間)
function attendanceValues = ShiftValues(attendanceValues)
% attendanceValues: Array contains 4 elements recording attendence for the last 4 shows
% Change indexing values
attendanceValues(1:4) = attendanceValues(2:4);
attendanceValues = circshift(attendanceValues,-1)
end
  1 件のコメント
zachary stallings
zachary stallings 2017 年 3 月 29 日
i figured it out all i needed to do was chance the indexing values to: attendanceValues(1:1) = attendanceValues(2:2); attendanceValues(2:2) = attendanceValues(3:3); attendanceValues(3:4) = attendanceValues(4:4);

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 3 月 29 日
attendanceValues(1:4) = attendanceValues(2:4);
has four output locations, #1, #2, #3, #4, but only 3 input locations, #2, #3, and #4 . That statement cannot succeed.
If you want to copy 3 input values then you need 3 output locations.
  5 件のコメント
DGM
DGM 2024 年 2 月 8 日
We assume that the vector always contains exactly 4 elements. The vector is left shifted such that the last element is retained, and the first element is discarded. If the input vector is called A, then the output vector is
A([2:4 4]) % note that there are still 4 elements here, not just 3
Walter Roberson
Walter Roberson 2024 年 2 月 8 日
You are copying three input locations. Adjust the assignment so that you have three output locations
attendanceValues(ThreeOutputLocations) = attendanceValues(2:4);
carefully choose ThreeOutputLocations

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by