Create a matrix/array with values in irregular order/shape

21 Views Asked by At

I am currently making a heat transfer model on Scilab and have basically no knowledge of programming to do it. I need to create an.... array/matrix?... with specific formulas (to find the temperature values) on specific places of the 2D matrix. I attach an image of the model I am working and the placing of each formula to give a better idea. Each square has a different number indicating I need to place a different formula on that specific place and the zeroes are blank spaces that don't have any value.

Spaces in matrix to input different formulas

My question is: How can I tell Scilab more efficiently to place each formula on specific squares?

I know I can make: For i=2:ny-1 ...For j=1 to place a formula on the first column from the second row until the second to last row.

But I want to know how to fill in all the spaces more efficiently so that I don't lose so much time making for ...after for.... after for....and so on for each square or rectangle I need to fill in. Can anyone tell me a more efficient way?

I tried something like this:

`
For i=1
For j=1
T(i,j)=....
//To place the formula of T() for the upper left lone corner
//Then

For i=2:ny-1
For j=1
T(i,j)=....

//to place the formula of T() on the first column from the second row until the second to last row.
//And then 

For i=3:ny-1
For j=2
T(i,j)=....`

and so on until I can fill in all the spaces but it literally takes hours

1

There are 1 best solutions below

0
Stéphane Mottelet On

For consecutive part of rows of columns use the range indexing, e.g.

For i=3:ny-1
For j=2
T(i,j)=....

should be stated as

T(3:ny-1,2) = ...