how can i find the error in my function please

Hello everybody! i have this problem to solve i did it that way and mark error so i would to know the best way to do it. Write a function called flip_it that has one input argument, a row vector v, and one output argument, a row vector w that is of the same length as v. The vector w contains all the elements of v, but in the exact opposite order. For example, is v is equal to [1 2 3] then w must be equal to [3 2 1]. You are not allowed to use the built-in function flip. here my function
function [z]= flip_it (x)
z = size(x)
z = x(:)
end
% my solution isn t correct but i can t see the error
hopefully somebody could be me. thanks in advance Ann

Answers (1)

Your current code simply returns the input as a column vector in the same order ... it does nothing to "flip" the actual element order.
Your instructor likely wants you to write some type of loop to create the output w from the input v. An outline would be as follows:
function [w] = flip_it (v)
w = v; % <-- pre-allocate w to the same class and size of v.
n = numel(v); % <-- the number of elements of v
for k=1:n
w(k) = ______; % <-- you need to figure out what to put here
end
end

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 23 Apr 2017

Commented:

on 24 Apr 2017

Community Treasure Hunt

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

Start Hunting!