I need assistance with a MATLAB myMakeSize question

1 回表示 (過去 30 日間)
Jason Robert Voris
Jason Robert Voris 2022 年 3 月 17 日
編集済み: Arif Hoq 2022 年 3 月 17 日
Need help with this question
Write a function with header [out] = myMakeSize10 (x), where x is an array and out is the first 10
elements of x if x has more than 10 elements, and out is the array x padded with enough zeroes
to make its length 10 if x has less than 10 elements.
Test Cases
>>A = myMakeSize10 (1:2)
A=
1 2 0 0 0 0 0 0 0 0

採用された回答

Arif Hoq
Arif Hoq 2022 年 3 月 17 日
編集済み: Arif Hoq 2022 年 3 月 17 日
x=1:5;
out=myMakeSize10(x)
out = 1×10
1 2 3 4 5 0 0 0 0 0
%
function y = myMakeSize10 (x)
if numel(x)>=10
y=x(1:10);
elseif numel(x)<10
y=[x zeros(1,10-numel(x))];
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by