フィルターのクリア

Adding elements to an array

4 ビュー (過去 30 日間)
Max
Max 2015 年 11 月 7 日
編集済み: Stephen23 2015 年 11 月 7 日
say I have an array
x=[0,0,2,3,4]
and a code
for n=1
if (10^n)*p<q
n=n+1;
elseif (10^n)*p>q
break
end
end
is there a way to add an extra 0 to the start of x if my n value goes up. for example. If n is one x=[0,0,2,3,4] and if n is 2 x=[0,0,0,2,3,4] and if n=3 x=[0,0,0,0,2,3,4] and so on. Thanks for the help.

採用された回答

Stephen23
Stephen23 2015 年 11 月 7 日
編集済み: Stephen23 2015 年 11 月 7 日
new_x = [zeros(1,n-1),x]

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by