where is the error ?

function [ vmin ] = mini(vect)
%MINI retourne le minimum d’un vecteur
n = numel(vect);
if n == 0
vmin = [];
else
vmin = vect(1);
for k = 2:n
if vect(k) < vmin
vmin = vect(k);
end
end
end
end
function [ vmax ] = maxi(vect)
%MAXI retourne le maxiimum d’un vecteur
n = numel(vect);
if n == 0
vmax = [];
else
vmax = vect(1);
for k = 2:n
if vect(k) > vmax
vmax = vect(k);
end
end
end
end

8 件のコメント

Walter Roberson
Walter Roberson 2018 年 12 月 2 日
what error are you encountering ?
KHAIF HICHEM
KHAIF HICHEM 2018 年 12 月 2 日
show this :
??? Input argument "vect" is undefined.
Error in ==> mini at 3
n = numel(vect); if n == 0, vmin = []; else vmin =
Adam Danz
Adam Danz 2018 年 12 月 2 日
編集済み: Adam Danz 2018 年 12 月 2 日
If your function breaks the first time it's sole inputs is accessed and the error is that the input variable 'vect' is undefined, that suggests you're running the function without an input.
Image Analyst
Image Analyst 2018 年 12 月 2 日
You aren't just clicking the green Run triangle without passing in vect are you???
Adam Danz
Adam Danz 2018 年 12 月 2 日
That's my bet (what Image Analyst said). If you'd like to run your code with default values for when there are no inputs specified, add this to the top of your code.
if nargin == 0
vect = [1 2 3 4 5]; %whatever your default values are
warning('Default values entered in %s.m', mfilename)
end
KHAIF HICHEM
KHAIF HICHEM 2018 年 12 月 2 日
2018-12-02_203452.jpg
Walter Roberson
Walter Roberson 2018 年 12 月 2 日
defining the variable in the base workspace is not enough .you need to go to the command line and
mini(v)
KHAIF HICHEM
KHAIF HICHEM 2018 年 12 月 3 日
can you show me ho to do ?

回答 (1 件)

M
M 2018 年 12 月 3 日
編集済み: M 2018 年 12 月 3 日

0 投票

In the command line, where you defined v, call the function this way:
>> v= [1 2 3 ;4 5 6];
>> mini(v)

この質問は閉じられています。

製品

タグ

質問済み:

2018 年 12 月 2 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by