Adding Zero to the first index of an array

27 ビュー (過去 30 日間)
Shahab Khan
Shahab Khan 2020 年 6 月 17 日
コメント済み: Shahab Khan 2020 年 6 月 17 日
I have an array
A = [1 2 3 -3 -2 -1 0 0 0]
of
size 1x9
I am trying to add zero at first index of this array. The result should be
Result = [0 1 2 3 -3 -2 -1 0 0 0]
Making the size of array
1x10
I have tried
A(1,:)=[];
Also
Idx=[1];
c=false(1,length(A)+length(Idx));
c(Idx)=true;
result=nan(size(c));
result(~c)=A;
result(c)=0
They both does now work for me.
Can someone guide me on this.

回答 (1 件)

David Hill
David Hill 2020 年 6 月 17 日
Result=[0 A];
  1 件のコメント
Shahab Khan
Shahab Khan 2020 年 6 月 17 日
Thank you. After your answer, I figure out why i was having problem. My array was vertical not horizental. I have transposed it and it worked. Thanks.

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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by