cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

How to extract non zero submatrix to a matrix table

Bartz87
1-Visitor

How to extract non zero submatrix to a matrix table

test.bmp

ACCEPTED SOLUTION

Accepted Solutions
StuartBruff
23-Emerald III
(To:Bartz87)

Neptali Barte wrote:

Yes, it works! Thanks Raiko. My another problem is that when I add more values in the columns of the 1st row only (See snapshot). It only gets the first row only. I want to include in the results the values of the second to the last row where there is a value even when there are zeroes below the 1st row.

Change your last line to

submatrix(test,min(I),max(I),min(J),max(J))

Stuart

View solution in original post

8 REPLIES 8
wayne
12-Amethyst
(To:Bartz87)

Use submatirx()

tmp12.gif

Bartz87
1-Visitor
(To:wayne)

Yup, the answer is quite correct but my goal is that, I don't want to update or change the value inside the submatrix function everytime I add values to either the rows or colums of "test" table. "test" is actually an excel component that I made with an output range say A1:F100. Anytime, I want to add values in the rows and columns in ascending order, the remaining cells in the range will be zero. An I only wanted to get the values in the cells that have an input in excel component. Do somebody have a function to do this?

Raiko
17-Peridot
(To:Bartz87)

Hello Neptali,

this function does the trick. However, if the pattern of the non-zero values is irregular (e.g. interspersed with zeros) it will generate an array that still contains some zeros.

Raiko

Bartz87
1-Visitor
(To:Raiko)

I'm using an excel component for the table and I got the below error in red. Why?

test2.bmp

StuartBruff
23-Emerald III
(To:Bartz87)

Neptali Barte wrote:

I'm using an excel component for the table and I got the below error in red. Why?

Because you have i counting columns instead of rows (and j counting rows instead of columns). the index test[i,j identifies row i, column j. Change them round and swap q and p in your submatrix call.

Stuart

PS,

a. There is no need to add the <>0 test after the IsString call; Mathcad treats all non-zero values as true and as IsString evaluates to 1 for a string, then it will be (by definition) not equal to zero. I don't think you need the test anyway, all you're after is non-zero elements and a string is <> 0.

b. There is no need to assign the result of submatrix to W; it's redundant as you don't use W and Mathcad will simply return the value of the submatrix if you remove the W<- bit.

Raiko
17-Peridot
(To:StuartBruff)

Hello Stuart,

thanks for the remarks. You're right, some of the code is redundant.

Raiko

P.S.

Neptali, does the function work now?

Bartz87
1-Visitor
(To:Raiko)

Yes, it works! Thanks Raiko. My another problem is that when I add more values in the columns of the 1st row only (See snapshot). It only gets the first row only. I want to include in the results the values of the second to the last row where there is a value even when there are zeroes below the 1st row.

test.bmp

StuartBruff
23-Emerald III
(To:Bartz87)

Neptali Barte wrote:

Yes, it works! Thanks Raiko. My another problem is that when I add more values in the columns of the 1st row only (See snapshot). It only gets the first row only. I want to include in the results the values of the second to the last row where there is a value even when there are zeroes below the 1st row.

Change your last line to

submatrix(test,min(I),max(I),min(J),max(J))

Stuart

Announcements

Top Tags