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
23 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
Réponses (1)
Walter Roberson
le 29 Mar 2017
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 commentaires
DGM
le 8 Fév 2024
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
le 8 Fév 2024
You are copying three input locations. Adjust the assignment so that you have three output locations
attendanceValues(ThreeOutputLocations) = attendanceValues(2:4);
carefully choose ThreeOutputLocations
Voir également
Catégories
En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!