Stack function - Not working as in the Beam.sm example - Сообщения
The worksheet will very similar to the Beam.sm example (but will do some more), and I'm doing pretty much the same that is done there when I don't
have a clue on how to do something.
I'm trying to use the stack function to put all rows of a loop in a single matrix, just like is in Beam.sm, but, the result isn't the same. I attached an image, where in the left side there's the best code I managed to do at the moment (gray), and in the right side is a code which is basically a copy of the code in the example, but using my functions. The code in example only show the last iteration, while my code have a vector of submatrices. None is the desirable answer.
The function in the example creates a single matrix with all the elements of the loops' vector, but it's not doing the same in my worksheet. Does anyone have an idea about why isn't it working?
Danilo Monteiro
WroteI'm creating a worksheet that will draw the forces acting on a beam and calculate reactions, moments, etc.
The worksheet will very similar to the Beam.sm example (but will do some more), and I'm doing pretty much the same that is done there when I don't
have a clue on how to do something.
I'm trying to use the stack function to put all rows of a loop in a single matrix, just like is in Beam.sm, but, the result isn't the same. I attached an image, where in the left side there's the best code I managed to do at the moment (gray), and in the right side is a code which is basically a copy of the code in the example, but using my functions. The code in example only show the last iteration, while my code have a vector of submatrices. None is the desirable answer.
The function in the example creates a single matrix with all the elements of the loops' vector, but it's not doing the same in my worksheet. Does anyone have an idea about why isn't it working?
Danilo Monteiro
It's quite easy; use a 2 arguments stack function and put as first argument the ouput matrix (see the screenshots)
Using a single argument the stack function converts the argument from number to matrix if the argument is a number, otherwise nothing changes.
regards,
w3b5urf3r
WroteWroteI'm creating a worksheet that will draw the forces acting on a beam and calculate reactions, moments, etc.
The worksheet will very similar to the Beam.sm example (but will do some more), and I'm doing pretty much the same that is done there when I don't
have a clue on how to do something.
I'm trying to use the stack function to put all rows of a loop in a single matrix, just like is in Beam.sm, but, the result isn't the same. I attached an image, where in the left side there's the best code I managed to do at the moment (gray), and in the right side is a code which is basically a copy of the code in the example, but using my functions. The code in example only show the last iteration, while my code have a vector of submatrices. None is the desirable answer.
The function in the example creates a single matrix with all the elements of the loops' vector, but it's not doing the same in my worksheet. Does anyone have an idea about why isn't it working?
Danilo Monteiro
It's quite easy; use a 2 arguments stack function and put as first argument the ouput matrix (see the screenshots)
Using a single argument the stack function converts the argument from number to matrix if the argument is a number, otherwise nothing changes.
regards,
w3b5urf3r
Hello, I tried the way you told me, but Smath said that the function is undefined (attached).

But then, I defined a initial matrix and it worked! Thank you very much!

Don't worry... I think that you have forgot to initialize the output matrices

You can create a 2x1 matrix before the for statement (and then after the loop you need to make a submatrix from the 2nd to the last row) or you can add an if/else condition inside the loop that exclude the stack at the first loop (I prefer the second solution but it's matter of taste)
[EDIT]
WroteBut then, I defined a initial matrix and it worked! Thank you very much!
![]()
Good, you're welcome

best regards,
w3b5urf3r
Wrote... or you can add an if/else condition inside the loop that exclude the stack at the first loop ...
No need for that; you only have to initialize the matrix like this:
[MATH lang=eng]Setas:matrix(0,2)[/MATH]
WroteNo need for that; you only have to initialize the matrix like this:
[MATH lang=eng]Setas:matrix(0,2)[/MATH]
Nice solution

WroteWroteNo need for that; you only have to initialize the matrix like this:
[MATH lang=eng]Setas:matrix(0,2)[/MATH]
Nice solution![]()
Indeed...
Implemented

-
Новые сообщения
-
Нет новых сообщений