How to generalize this code?
Afficher commentaires plus anciens
I'm working with WDS (Water Distribution System) at the moment I'm using a small one so I can write every matrix manually... but must exist something easyer! Example: P is matrix of pressure:
P1=[P1(:,2),P1(:,1),P1(:,3),P1(:,4),P1(:,5),P1(:,6)];
P2=[P2(:,2),P2(:,1),P2(:,3),P2(:,4),P2(:,5),P2(:,6)];
P3=[P3(:,2),P3(:,1),P3(:,3),P3(:,4),P3(:,5),P3(:,6)];
P4=[P4(:,2),P4(:,1),P4(:,3),P4(:,4),P4(:,5),P4(:,6)];
P5=[P5(:,2),P5(:,1),P5(:,3),P5(:,4),P5(:,5),P5(:,6)];
P6=[P6(:,2),P6(:,1),P6(:,3),P6(:,4),P6(:,5),P6(:,6)];
P7=[P7(:,2),P7(:,1),P7(:,3),P7(:,4),P7(:,5),P7(:,6)];
P8=[P8(:,2),P8(:,1),P8(:,3),P8(:,4),P8(:,5),P8(:,6)];
P9=[P9(:,2),P9(:,1),P9(:,3),P9(:,4),P9(:,5),P9(:,6)];
P0=[P0(:,2),P0(:,1),P0(:,3),P0(:,4),P0(:,5),P0(:,6)];
How can I write this code for N matrix of pressure?
5 commentaires
The simplest and best answer is "do not create variables dynamically". That is a totally Lunatix way of programming, and should be avoided.
If you tell us exactly what you are trying to achieve then we can show you better, neater and robuster ways of doing it.
Lunatix
le 22 Fév 2016
Stephen23
le 22 Fév 2016
@Lunatix: that is exactly what you should not do. Read my answer to know why.
Lunatix
le 22 Fév 2016
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!