Matlab cross referencing matrix and table elements

Click For Summary
SUMMARY

The discussion focuses on implementing a solution in MATLAB to cross-reference reactions from a table with interactions defined in a matrix. The user has four column vectors representing reactions and a 111x111 matrix indicating interactions between compounds. The goal is to add six columns to the existing table, marking interactions as 1 or 0 based on the matrix. The user seeks assistance with coding this logic effectively, particularly in creating new columns and ensuring proper cross-referencing between the table and matrix.

PREREQUISITES
  • Understanding of MATLAB programming, specifically loops and conditional statements.
  • Familiarity with matrix operations in MATLAB, including indexing and resizing.
  • Knowledge of chemical reaction representation in tabular form.
  • Basic understanding of MATLAB's array manipulation functions.
NEXT STEPS
  • Learn how to implement conditional logic in MATLAB for matrix indexing.
  • Research MATLAB functions for dynamically resizing matrices, such as 'zeros' and 'size'.
  • Explore MATLAB documentation on matrix manipulation techniques for efficient coding.
  • Investigate alternative methods for appending columns to matrices in MATLAB.
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly those working in computational chemistry, data analysis, or anyone needing to manipulate large datasets involving matrix operations and conditional logic.

hoffmann
Messages
65
Reaction score
0
hi all, here's an interesting problem I've been working on in MATLAB. any help would be appreciated.

i have four column vectors of length ~11000 (table1):

in1 in2 out1 out2
11 4 101 47
1 8 111 9
38 1 1 39
...

i also have a matrix with dimensions 111x111 (matrix1):

c1 c2 c3 c4 ...
c1 0 0 0 1
c2 0 0 1 1
c3 0 1 0 0
c4 1 1 0 0
...

the first four column vectors in table1 represent reactions (read across columns) in which compounds 1 through 111 can participate in. compound 1 in table1 represents a compound with zero mass, so essentially a nonexistent compound. e.g. 11+4=101+47 is the reaction contained in the first row of table 1.

the first reaction in table1 can be classified as A+B=C+D with six possible interactions between the compounds: A-B, A-C, A-D, B-C, B-D, C-D. the second reaction can be classified as A=C+D with its 3 appropriate interactions. the third reaction can be classified as A=D with its 1 interaction.

i basically would like to add 6 more columns to table1 denoting whether an interaction existing in the reaction exists in matrix1. put a 1 in the column when an interaction exists and a 0 otherwise. i need to do this for all reactions in table1. the values in table1 denote the indices of the compounds which should correspond to the row and column labels in matrix1 (i basically added a 'c' tag in front for readability).

i'm having difficulty coding this problem. i would approach it using something like:
for i=1:length(in1)
if matrix1(A,B)==1 && table1(A,B)~=0 %here's where it gets iffy for me
% I'm unsure on how to create columns and make sure i am cross referencing the %elements of table1 and matrix1 properly.

i would appreciate any help since I've tried to conceptualize this problem and believe i am doing so correctly. any more efficient methodologies would be welcome. thanks!
 
Physics news on Phys.org
I'm not so sure about efficient, but oh well. One way of doing this would be to create a new 2D matrix called table2 using the zeros instruction:

>> table2=zeros(111, 10);

or, if you were looking for more expandability:

>> table2=zeros((size(table1))(1),(size(table1))(2)+4);

and then copy over table1 to table2:

>> table2(1:111, 1:6) = table1

I'm unaware of any function that allows you to EASILY tack on extra columns (I suppose you could transpose, add some rows by putting zeros in the new rows, and then transpose back) but the following Mathworks Matlab documentation page may nevertheless be of some benefit to you (Resizing and reshaping matrices):

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f1-85766.html
 
Last edited by a moderator:

Similar threads

  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 41 ·
2
Replies
41
Views
10K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K