Double indexing in FOR Loop
古いコメントを表示
Hello, friends
There is a problem that I cannot solve. I know that the code below is not right. I wrote it like that to be more understandable what I need to do. I need to create a cycle that will make new polynomial functions with indexing (p1,p2,p3..and so on). Each new polynom is using previous polynom for calculating the new members, which already have their own indexing (p(1),p(2)..), so MatLab doesnt let me to provide 2 indexing at the same time. Could you please help me somehow? Thank you very much and have a nice day!
p0 = app.PolynomEditField.Value;
p0 = str2num(p0);
for i = 1:(length(p0)-1)
p{i} = p0;
p{i}(1) = (p{i-1}(1))^2;
p{i}(2) = (-1)*((p{i-1}(2))^2-2*(p{i-1}(1))*(p{i-1}(3)));
p{i}(3) = (p{i-1}(3))^2 - 2*(p{i-1}(2))*(p{i-1}(4)) + 2*(p{i-1}(1))*(p{i-1}(5));
p{i}(end-1) = ((p{i-1}(end-1))^2-2*(p{i-1}(end-2))*(p{i-1}(end)))*((-1)^(length(p{i-1})-2));
p{i}(end) = ((p{i-1}(end))^2)*((-1)^(length(p{i-1})-1));
res = char(sprintf(['Posloupnost polynomů: %s'],p{i}));
app.VsledkyTextArea.Value = res;
end
2 件のコメント
Rishik Ramena
2021 年 3 月 16 日
Do you need values from the previous iteration, or just another loop variable that increments with the loop?
Macarena Santillan
2021 年 7 月 7 日
I have a similar issue. I need values from previus iteration and another loop variable that increments with the loop but they depend on previous values. How would you do it for each/both cases? Thank you!
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!