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

Stephen23
Stephen23 2016년 2월 22일
편집: Stephen23 2016년 2월 22일
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.
I need to create N matrix, I want to call the first matrix P1 the second P2 until P'N'. somethin like this:
N=10
For i=1:N
P(i)=[1,5,9]
end
I would like to have back
P1=[1,5,9]
P2=[1,5,9]
...
P10=[1,5,9]
Stephen23
Stephen23 2016년 2월 22일
@Lunatix: that is exactly what you should not do. Read my answer to know why.
Lunatix
Lunatix 2016년 2월 22일
I'm sorry, now I understand what you told me before! I'm trying to use cell array... I'm not a programmer and I use matlab as a calculator! PS I'm going to translate my work using cell array than, maybe, I can show you my code! And you can tell me if it is the right way...
Stephen23
Stephen23 2016년 2월 22일
편집: Stephen23 2016년 2월 22일
Using a cell array is a great idea. If you have any questions or want a clarifications then create a new question (rather than continuing this thread).

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2016년 2월 22일

편집:

2019년 6월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by