code is showing error with some inputs

function w=flip_it(v)
m=size(v)
w=v(end:-1:v(1,1));
end

3 件のコメント

James Tursa
James Tursa 2018 年 4 月 11 日
Is this supposed to work on vectors and matrices and multi-dimensional arrays?
Guillaume
Guillaume 2018 年 4 月 11 日
And what is the point of
m=size(v)
which is completely unused.
In any case, there are many inputs with which the given work will not work, something as simple as v=0 will error, but since there's no explanation of what the code should do how can we tell what is a coding error.
Ashay Shukla
Ashay Shukla 2018 年 4 月 13 日
thanks

サインインしてコメントする。

 採用された回答

James Tursa
James Tursa 2018 年 4 月 11 日
編集済み: James Tursa 2018 年 4 月 11 日

0 投票

Why are you using v(1:1) as an index into v? Did you mean this instead?
w = v(end:-1:1);
Also, it is not clear from your post whether your code is supposed to work for only vectors, or for matrices and multi-dimensional arrays also. If it is the latter, then you will need different code to handle those extra dimensions properly.

1 件のコメント

Ashay Shukla
Ashay Shukla 2018 年 4 月 13 日
thanks.I got the answer

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by