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
답변 (1개)
James Tursa
2017년 4월 23일
편집: James Tursa
2017년 4월 23일
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
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!