Info

この質問は閉じられています。 編集または回答するには再度開いてください。

If i have a random vector, e.g [2 4 3 4 3 4] how would i code a script to give how many times the max value is attained? I know the answer is obviously 3 here but what would the input be for any random vector? Many thanks in advance.

1 回表示 (過去 30 日間)
Dermot McCloskey
Dermot McCloskey 2014 年 10 月 31 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
%% QUESTION 2 u=input('Give a vector: ')
v=u(2:2:end); disp('The new vector v= ') disp(v)
vmin=min(u); disp('Min of u=') %To obtain minimum value of vector 'u' disp(vmin)
vmax=max(u); disp('Max of u=') %To obtain the maximum value of vector 'u' disp(vmax)
vavr=sum(u); disp('The sum of the elements of u=') disp(vavr)
BUT need final code to find how many times max value is attained for any vecor u!!!!!

回答 (1 件)

Matt Tearle
Matt Tearle 2014 年 10 月 31 日
Easiest way: nnz(u == vmin)

Community Treasure Hunt

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

Start Hunting!

Translated by