for loop index variable change inside the loop[

I have a very basic coding question but little tricky . Any help would be appreciated
The question follows :
a = [ 3 7 2 6]
x = large size vector
for i = a
for j = x(a,:)
... expression
.. expression
c = find (a > j)
if c ~0
a (c )= a (c) -1;
end
end
end
But for loop index i not changing according to change in variable a. As i came to know from mathwork community it can't be changes . Could some one assit me how to approach this problem.

5 件のコメント

KSSV
KSSV 2022 年 1 月 7 日
Why don't you show us what you expect with a small example with data?
Simon Chan
Simon Chan 2022 年 1 月 7 日
Sample data can help a lot, below is what I guess:
Na = length(a);
for i = 1:Na
value_a = a(i); % Get the value from matrix a one by one
row_X = X(value_a,:); % Extract the row from matrix X based on row number a
c = find (value_a > row_X);
if c ~=0
row_X(c)= row_X(c)-1; % Modify the matrix X after comparison
end
end
RAKESH KUMAR TOTA
RAKESH KUMAR TOTA 2022 年 1 月 7 日
Sure .
a = [ 3 7 2 6]
let us suppose x = [ ] 10*4 size vector where array 'a' each cell are row position of x
for i = a
for j = x(a,:)
x(i,:) = []
c = find (a > j)
if c ~0
a (c )= a (c) -1;
end
end
end
Actually the data is too large to put it here.
If you need more specific then i have to thing and frame a small example. Anyway please let me know if you need more .
Thank you for your prompt response
RAKESH KUMAR TOTA
RAKESH KUMAR TOTA 2022 年 1 月 11 日
Thank you it served purpose how to accpet both answers @KSSV and @Simon Chan
Rik
Rik 2022 年 1 月 11 日
Your comment is a bit confusing to me. Did KSSV and Simon solve the problem for you? They posted comments (not answers), so you can't mark them as accepted answer.

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

回答 (1 件)

Rik
Rik 2022 年 1 月 7 日

0 投票

Once a for loop has started you can no longer change the expression it is based on.
You will have to rewrite your for loop as a while loop.

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 1 月 7 日

コメント済み:

Rik
2022 年 1 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by