Indexing array element with for loop with specified step size
Show older comments
Hi MATLAB users,
I have a data file for 1 row and 332 columns. The first column correspond to time vale and rest 331 coliumns correspond to coordinate values of atoms of a molecule. I want to multiply each atom by certain value to get my output. But since my column numbers are odd, I am not able to specify the exact step size in the for loop.
Example,
My input file looks like the following
|<- Molecule 1 ->| |<- Molecule 2 ->| ................ <- Molecule 331->
Time_value ATOM1 ATOM2 ATOM3 ATOM4 ATOM1 ATOM 2ATOM3 ATOM4.....................
I have to multiply ATOM1 by 2, ATOM2 by 3, ATOM3 by 5 and ATOM4 by 8.
Following is my code:
for i = 2:4:331
X = 2*ATOM1 + 3*ATOM2 + 5*ATOM3 + 8*ATOM4;
end
I am not able to get the correct output as desired.
It will be very nice if anyone can help me.
Thanks in advance !
1 Comment
Cris LaPierre
on 24 Dec 2021
How is your data stored in each column? You example suggests that each of the 331 columns contain 4 atom coordinates. Is that correct?
Answers (0)
Categories
Find more on Image Quality in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!