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);
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 件)
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
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
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 Exchange で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!