calling all the elements of a matrix consecutively

1 回表示 (過去 30 日間)
Nicholas
Nicholas 2013 年 10 月 27 日
編集済み: Azzi Abdelmalek 2013 年 10 月 27 日
I need to call every element of a vector consecutively except the 'i' element I'm on. for example if i am using two for loops and my vector is V = [1,2,3,4,5]
[n,m]=size(V)
for i=1:m
for j=1:m-1
when i=1, i need to call 2 then 3 then 4 then 5
but for example when i=4, I need to call 1 then 2 then 3 then 5
I need this to work for any size vector because i am going to try to implement this in my Lagrangian polynomial interpolation function.
so again an example for i=3, my four j's in the second for loop should be 1 then 2 then 4 then 5
  3 件のコメント
Nicholas
Nicholas 2013 年 10 月 27 日
編集済み: Nicholas 2013 年 10 月 27 日
I just mean for my second for loop each iteration has to be a consecutive value from my vector V, skipping whatever value is in the ith place for my first for loop...for example for i = 3 I need my second for loop to iterate 1 then 2 then 4 then 5....let me know if this doesnt make sense.
Nicholas
Nicholas 2013 年 10 月 27 日
編集済み: Nicholas 2013 年 10 月 27 日
here is another example...
V = [ 1 4 9 5]
[n,m]=size(V)
for i=1:m % m equals the number of values in my vector
for j=1:m-1
when i is 1, my second for loop needs to iterate 4 then 9 then 5
when i is 2 my second for loop needs to iterate 1 then 9 then 5

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

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 27 日
編集済み: Azzi Abdelmalek 2013 年 10 月 27 日
V = [ 1 4 9 5]
for ii=1:numel(V)
q=V;
q(ii)=[]
for jj=q
  1 件のコメント
Nicholas
Nicholas 2013 年 10 月 27 日
AWESOME! thank you very much

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by