Effacer les filtres
Effacer les filtres

Is it possible to make a loop to run another loop?

2 vues (au cours des 30 derniers jours)
Lev Mihailov
Lev Mihailov le 21 Juil 2020
Commenté : Lev Mihailov le 21 Juil 2020
Hello! I have a large matrix that I need to work with. Now I select a separate vector and work with it in a loop
Xvector=Xmatrix(:,1);
for j=1:100 % 100 - 100 is the length of the column
x=mean(mean(Xvector(a(j):a(j+1)));) % a - the values ​​I'm working with
end
now i want to do so
for i=1:1000 % 1000 is the length of the lines
Xvector(:,i)=Xmatrix(:,i);
for j=1:100 % 100 - 100 is the length of the column
x=mean(mean(Xvector(a(j):a(j+1)));) % a - the values ​​I'm working with
end
end
only the last value (last column) counts to me.
how can I fix this? ps I understand the cycle will be long, but manually entering everything will take a very long time
  2 commentaires
Walter Roberson
Walter Roberson le 21 Juil 2020
for i=1:1000 % 1000 is the length of the lines
Xvector(:,i)=Xmatrix(:,i);
j = 100 % 100 - 100 is the length of the column
x(i) = mean(mean(Xvector(a(j):a(j+1)));) % a - the values I'm working with
end
Lev Mihailov
Lev Mihailov le 21 Juil 2020
a=[1:4:100];
Index exceeds the number of array elements (25).
Error in p (line 47)
x(i) = mean(mean(Xvector(a(j):a(j+1)))) % a - the values I'm working with

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by