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
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
Respuestas (1)
Walter Roberson
el 29 de Mzo. de 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 comentarios
DGM
el 8 de Feb. de 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
el 8 de Feb. de 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
Ver también
Categorías
Más información sobre Operators and Elementary Operations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!