Implement the body of the function rotationMatrix(),
Show older comments
function M = rotationMatrix( Size, Shift )
% Generate a square permutation matrix if size Size.
% The permutation is a right rotation - the ROR operation.
% That is the right-multiplication of a row-vector by this matrix performs
% a cyclic shift of vectors positions - the ROR operation.
% The scalar shift specifies how many positions to rotate
% if negative, a ROL operation is performed.
% You cannot use any toolbox functions of cycles,
% just indexing of an identity matrix.
HOW DO THIS? I CANT FIND SOMFTHING FOR THIS
9 Comments
Steven Lord
on 2 Nov 2022
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
Ian
on 2 Nov 2022
Ian
on 2 Nov 2022
Steven Lord
on 2 Nov 2022
Two suggestions:
1) If this is your first time writing MATLAB code, I do strongly recommend walking through at least the first couple sections in the MATLAB Onramp tutorial I linked above. It's designed to help new users familiarize themselves with how to work in MATLAB, and I'm 99% sure there's a section on how to write script files. Functions in general are a little more complicated, but your assignment gives you the definition line of the function (the information the caller of the function provided you, Size and Shift, and the information the caller wants you to return to them, M) and that's much of the complication taken care of.
2) Before you write any code, write comments outlining the steps you're going to follow in words. Treat those comments like a recipe; this will make sure you don't make a mistake like leaving the sugar out of a cookie recipe or forgetting to create a variable you're going to need at a later step. If your textbook offers some pseudocode for creating a rotation matrix, copy those steps as the "recipe" for your function.
Then write the code for each step, one at a time, making sure it does what the "recipe" says it should. If you don't understand how to write the code for any of the steps, break it down into "bite sized" substeps.
Jan
on 2 Nov 2022
@Ian: What does this mean: "this is first ex,"? What is the posted code? Your try to solve the question, or a code snippet taken from anywhere?
How does "Implement the body of the function rotateRight()," match your statement: "bc in homework nobodysay about write a new script"?
It is not clear to me, where a "rotation matrix" come into play.
Currently the only clear part of the question is the original text of your homework assignment. Note that the forum will not solve your homework, because this is not efficient. Post what you have tried so far and ask a specific question related to Matlab. Then you can get support here.
You need 2 lines of code only to create such a matrix.
Steven Lord
on 2 Nov 2022
I interpreted "this is first ex" to be "this is the first exercise for the course."
Ian
on 2 Nov 2022
Jan
on 2 Nov 2022
@Steven Lord: Thanks.
@Ian: Please note that many members of this forum do not speak English natively. Then smart abbreviations are not cool, but confusing.
Ian
on 2 Nov 2022
Answers (1)
Hint:
v = 1:15
shift = 3;
vShifted = [v(end-shift+1 : end), v(1:end-shift)]
shift = -3;
vShifted = [v(-shift+1 : end), v(1:-shift)]
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!