how do I select an atom using pymol? - visualization

I'm not sure if this is the right web page to ask...
I have a xyz file I have generated:
C 0 0 0
O 0 0 0.1
O 0 0 0.2
C 0 0 0.6
O 0 0 0.5
O 0 0 0.4
.
.
.
How can I select a specific atom in command line or measure the distance between two atoms (pymol)?

pymol select command is described in detail here:
http://www.pymolwiki.org/index.php/Property_Selectors
In your case, to select certain atom(s), you can use:
select C_atoms, name C # select all C atoms and name the selection C_atoms
select atom_4, id 4 # select the 4th atom in the file and name it atom_4
select idx_4, index 4 #
select rank_4, rank 4 #
as for the difference between rank, ID, index for atoms, see
http://www.mail-archive.com/pymol-users#lists.sourceforge.net/msg08503.html

I have sent an email to the pymol email-list. I need to find the ID of the atom/molecule I want (I'm sure there is a better way but I have used the gui interface) and then:
select id <num>
or
distance id<num>, id<num>
to measure distance

Related

"Heap exhausted, game over" message in wxMaxima - Does ccl will work for me?

everyone,
I'm trying to do some calculations and plot the results, but it seems that these are too heavy for Maxima. When I try to calculate N1 and N2 the program crashes when parameter j is too high or when I try to plot them, the program displays the following error message: "Heap exhausted, game over." What should I do? I've seen some people saying to try to compile Maxima with ccl, but I don't know how to do it or if it will work.
I usually receive error messages like:
Message from maxima's stderr stream: Heap exhausted during garbage collection: 0 bytes available, 16 requested.
Gen Boxed Unboxed LgBox LgUnbox Pin Alloc Waste Trig WP GCs Mem-age
0 0 0 0 0 0 0 0 20971520 0 0 0,0000
1 0 0 0 0 0 0 0 20971520 0 0 0,0000
2 0 0 0 0 0 0 0 20971520 0 0 0,0000
3 16417 2 0 0 43 1075328496 707088 293986768 16419 1 0,8032
4 13432 21 0 1141 70 955593760 838624 2000000 14594 0 0,2673
5 0 0 0 0 0 0 0 2000000 0 0 0,0000
6 741 184 34 28 0 63259792 1424240 2000000 987 0 0,0000
7 0 0 0 0 0 0 0 2000000 0 0 0,0000
Total bytes allocated = 2094182048
Dynamic-space-size bytes = 2097152000
GC control variables:
*GC-INHIBIT* = true
*GC-PENDING* = true
*STOP-FOR-GC-PENDING* = false
fatal error encountered in SBCL pid 13884(tid 0000000001236360):
Heap exhausted, game over.
Here goes the code:
enter code here
a: 80$;
b: 6*a$;
h1: 80$;
t: 2$;
j: 5$;
carga: 250$;
sig: -carga/2$;
n: 2*q*%pi/b$;
m: i*%pi/a$;
i: 2*p-1$;
i1: 2*p1-1$;
/*i1: p1$;*/
Φ: a/b$;
τ: cosh(x) - (x/sinh(x))$;
σ: sinh(x) - (x/cosh(x))$;
Ψ: sinh(x)/τ$;
Χ: cosh(x)/σ$;
Λ0: 1/(((i/2)^2+Φ^2*q^2)^2)$;
Λ1: sum((((i/2)^3*subst([x=(i*%pi/(2*Φ))],Ψ))/(((i/2)^2+Φ^2*q1^2)^2))*Λ0, p, 1, j)$;
Λ2: sum(((q1^3*subst([x=(q1*%pi*Φ)],Χ))/(((i/2)^2+Φ^2*q1^2)^2))*Λ1, q1, 1, j)$;
Λ3: sum((((i/2)^3*subst([x=(i*%pi/(2*Φ))],Ψ))/(((i/2)^2+Φ^2*q1^2)^2))*Λ2, p, 1, j)$;
Λ4: sum(((q1^3*subst([x=(q1*%pi*Φ)],Χ))/(((i/2)^2+Φ^2*q1^2)^2))*Λ3, q1, 1, j)$;
Λ5: sum((((i/2)^3*subst([x=(i*%pi/(2*Φ))],Ψ))/(((i/2)^2+Φ^2*q1^2)^2))*Λ4, p, 1, j)$;
Ζ0: sum(((q^3*subst([x=(q*%pi*Φ)],Χ))/(((i1/2)^2+Φ^2*q^2)^2))*Λ0, q, 1, j)$;
Ζ2: sum(((q^3*subst([x=(q*%pi*Φ)],Χ))/(((i1/2)^2+Φ^2*q^2)^2))*Λ2, q, 1, j)$;
Ζ4: sum(((q^3*subst([x=(q*%pi*Φ)],Χ))/(((i1/2)^2+Φ^2*q^2)^2))*Λ4, q, 1, j)$;
E: 200000$;
ν: 0.3$;
λ: (ν*E)/((1+ν)*(1-2*ν))$;
μ: E/(2*(1+ν))$;
a0: float(1/(b/2)*integrate(0, y, -(b/2), -h1/2)+1/b*integrate(sig, y, -h1/2, h1/2)+1/(b/2)*integrate(0, y, h1/2, (b/2)))$;
aq: float(1/(b/2)*integrate(0*cos(q*y*%pi/(b/2)), y, -(b/2), - h1/2)+1/(b/2)*integrate(sig*cos(q*y*%pi/(b/2)), y, -h1/2, h1/2)+1/(b/2)*integrate(0*cos(q*y*%pi/(b/2)), y, h1/2, (b/2)))$;
aq1: float(1/(b/2)*integrate(0*cos(q1*y*%pi/(b/2)), y, -(b/2), - h1/2)+1/(b/2)*integrate(sig*cos(q1*y*%pi/(b/2)), y, -h1/2, h1/2)+1/(b/2)*integrate(0*cos(q1*y*%pi/(b/2)), y, h1/2, (b/2)))$;
Bq: aq/((λ+μ)*subst([x=q*%pi*Φ],σ))+((16*Φ^4*q^2*(-1)^q)/((λ+μ)*%pi^2*subst([x=q*%pi*Φ],σ)))*sum(q1*aq1*(-1) ^q1*subst([x=q1*%pi*Φ],Χ)*(Λ1+(16*Φ^4/(%pi^2))*Λ3+((16*Φ^4/(%pi^2))^2)*Λ5), q1, 1, j)+(8*λ*Φ^3*q^2*(-1)^q*a0)/((λ+μ)*(λ+2*μ)*(%pi^3)*subst([x=q*%pi*Φ],σ))*sum(subst([x=i*%pi/(2*Φ)],Ψ)/(i/ 2)*(Λ0+(16*Φ^4/(%pi^2))*Λ2+((16*Φ^4/(%pi^2))^2)*Λ4), p, 1, j)$;
βp: -(2*λ*a0*(-1)^((i-1)/2))/((λ+μ)*(λ+2*μ)*(i/2)^2*%pi^2*subst([x=i*%pi/(2*Φ)],τ))-((32*λ*Φ^4*(i/2)^2*a0*(-1)^((i-1)/2))/((λ+μ)*(λ+2*μ)*%pi^2*subst([x=i*%pi/(2*Φ)],τ)))*sum(((subst([x=i1*%pi/(2*Φ)],Ψ))/(i1/2))*(Ζ0+Ζ2*((16*Φ^4)/%pi^2)+Ζ4*(((16*Φ^4)/%pi^2)^2)),p1,1,j)-((4*Φ*(i/2)^2*(-1)^((i-1)/2))/((λ+μ)*%pi*subst([x=i*%pi/(2*Φ)],τ)))*sum(q*aq*(-1)^q*subst([x=q*%pi*Φ],Χ)*(Λ0+Λ2*(16*Φ^4/%pi^2)+Λ4*(16*Φ^4/%pi^2)^2),q,1,j)$;
N1: (2*a0/a)*x+(λ+μ)*sum(Bq*((1+((n*a*sinh(n*a/2))/(2*cosh(n*a/2))))*sinh(n*x)-n*x*cosh(n*x))*cos(n*y),q,1,j)+(λ+μ)*sum(βp*((1-((m*b*cosh(m*b/2))/(2*sinh(m*b/2))))*cosh(m*y)+m*y*sinh(m*y))*sin(m*x),p,1,j)$;
N2: ((2*λ*a0)/(a*(λ+2*μ)))*x+(λ+μ)*sum(Bq*((1-((n*a*sinh(n*a/2))/(2*cosh(n*a/2))))*sinh(n*x)+n*x*cosh(n*x))*cos(n*y),q,1,j)+(λ+μ)*sum(βp*((1+((m*b*cosh(m*b/2))/(2*sinh(m*b/2))))*cosh(m*y)-m*y*sinh(m*y))*sin(m*x),p,1,j);
wxplot3d(N1, [x,-a/2,a/2], [y,-b/2,b/2])$;
wxplot3d(N2, [x,-a/2,a/2], [y,-b/2,b/2])$;
This is not a complete answer, since I don't know how this should work with wxMaxima: I would suggest that you ask the developers. However it's too long for a comment and I think might be useful to people, and it does answer the question of how you solve the heap-size limit for Maxima itself when using SBCL, at least when run on Linux or some other platform with a command-line.
As a note, I suspect that the underlying problem is not the heap size, but that the calculation is blowing up in some horrible way: the best fix is probably to understand what's blowing up and fix that. See Robert Dodier's answer, which is probably going to be a lot more helpful. However, if heap size is the problem, this is how you deal with it for Maxima.
The trick is that you can tell SBCL what the heap limit should be by passing it the --dynamic-space-size <MB> argument, and you can pas arguments through the maxima wrapper to do this.
Here is a transcript of Maxima, being run on Linux, with SBCL as a back end (this is a version built from source: the packaged version will I assume be the same):
$ maxima
Maxima 5.43.2 http://maxima.sourceforge.net
using Lisp SBCL 2.0.0
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) :lisp (sb-ext:dynamic-space-size)
1073741824
So, on this system the defaule heap limit is 1GB (this is SBCL's default limit on the platform).
Now we can pass the -X <lisp options> aka --lisp-options=<lisp options> option to the maxima wrapper to pass the appropriate option through to sbcl:
$ maxima -X '--dynamic-space-size 2000'
Lisp options: (--dynamic-space-size 2000)
Maxima 5.43.2 http://maxima.sourceforge.net
using Lisp SBCL 2.0.0
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) :lisp (sb-ext:dynamic-space-size)
2097152000
As you can see this has doubled the heap size.
If someone knows the answer for wxMaxima then please do add an edit to this answer: I can't experiment it because all my Linux VMs are headless.
Also not a complete answer here, but some more notes and pointers which I hope will help.
To make the problem easier for Maxima to digest, use only exact numbers (integers and ratios), and avoid float and numer. (Plotting functions will apply float and numer automatically.) I changed 0.3 to 3/10 and cut out the calls to float.
Also, try setting j to a smaller number (I tried j equal to 1) to try to work all the way through the problem before increasing it to 5 again.
Also, replace all sum and integrate with 'sum and 'integrate (i.e. noun expressions instead of verb expressions). Take a look at the summands and integrands to see if they look right. You can evaluate the sums and/or integrals or both via ev(expr, sum) or ev(expr, integrate) or ev(expr, nouns) to evaluate 'sum, 'integrate, or all noun expressions, respectively.
With j equal to 1, I get the following expression for N1:
(2500000*((-(13*cosh(%pi/6)
*((8503056*cosh(%pi/6)^2*sinh(3*%pi)^2)
/(9765625*%pi^4
*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))^2
*(cosh(3*%pi)-(3*%pi)/sinh(3*%pi))^2)
+(52488*cosh(%pi/6)*sinh(3*%pi))
/(15625*%pi^2*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))
*(cosh(3*%pi)-(3*%pi)/sinh(3*%pi)))
+324/25))
/(120000*%pi^2*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))
*(cosh(3*%pi)-(3*%pi)/sinh(3*%pi))))
+(13*sinh(3*%pi)
*((2754990144*cosh(%pi/6)^3*sinh(3*%pi)^2)
/(244140625*%pi^4
*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))^3
*(cosh(3*%pi)-(3*%pi)/sinh(3*%pi))^2)
+(17006112*cosh(%pi/6)^2*sinh(3*%pi))
/(390625*%pi^2
*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))^2
*(cosh(3*%pi)-(3*%pi)/sinh(3*%pi)))
+(104976*cosh(%pi/6))
/(625*(sinh(%pi/6)-%pi/(6*cosh(%pi/6))))))
/(22680000*%pi^2*(cosh(3*%pi)-(3*%pi)/sinh(3*%pi))^2)
+13/(35000*%pi^2*(cosh(3*%pi)-(3*%pi)/sinh(3*%pi))))
*sin((%pi*(2*p-1)*x)/80)
*((%pi*(2*p-1)*y*sinh((%pi*(2*p-1)*y)/80))/80
+(1-(3*%pi*(2*p-1)*cosh(3*%pi*(2*p-1)))
/sinh(3*%pi*(2*p-1)))
*cosh((%pi*(2*p-1)*y)/80)))
/13
+(2500000*((-(13*cosh(%pi/6)
*((344373768*cosh(%pi/6)^2*sinh(3*%pi)^3)
/(244140625*%pi^4
*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))
^2
*(cosh(3*%pi)-(3*%pi)/sinh(3*%pi))
^3)
+(2125764*cosh(%pi/6)*sinh(3*%pi)^2)
/(390625*%pi^2
*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))
*(cosh(3*%pi)-(3*%pi)/sinh(3*%pi))^2)
+(13122*sinh(3*%pi))
/(625*(cosh(3*%pi)-(3*%pi)/sinh(3*%pi)))))
/(1620000*%pi^3*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))^2))
+(13*sinh(3*%pi)
*((8503056*cosh(%pi/6)^2*sinh(3*%pi)^2)
/(9765625*%pi^4
*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))^2
*(cosh(3*%pi)-(3*%pi)/sinh(3*%pi))^2)
+(52488*cosh(%pi/6)*sinh(3*%pi))
/(15625*%pi^2*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))
*(cosh(3*%pi)-(3*%pi)/sinh(3*%pi)))
+324/25))
/(3780000*%pi^3*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))
*(cosh(3*%pi)-(3*%pi)/sinh(3*%pi)))
-13/(20000*%pi*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))))
*(((%pi*sinh(%pi/6))/(6*cosh(%pi/6))+1)
*sinh((%pi*x)/240)
-(%pi*x*cosh((%pi*x)/240))/240)*cos((%pi*y)/240))
/13-(25*x)/48$
Now in order to plot that, it should be a function of x and y only. However listofvars reports that it contains x, y, and p. Hmm. I see that βp has a summation over p1 but it contains Ζ0, which contains Λ0, which contains p. Is the summation over p1 supposed to be over p? Is the summand supposed to contain p1 instead of p?
Likewise it appears that N2, after evaluating the sums and integrals with j equal to 1, contains p.
Maybe you need to rework the formulas somewhat? I don't know what the correct form might be.

How to traverse M*N grid in KDB

How to traverse m*n grid in Qlang, you can traverse up , down or diagonally.
to find how many possible ways end point can be reached.
Like Below :
0
|
------- ------
| | |
( 0 1) (1 1) (1 0)
| . |
------ ----- ------ -----
| | . | |
( 0 1) (1 0) ( 1 1) (2 0)
....
(2 2) ..................... (2 2)
One way of doing it using .z.s to recursively call the initial function with different arguments and summing to give total number of paths.
f:{
// When you reach a wall, there is only one way to corner so return valid path
if[any 1=(x;y);:1];
// Otherwise spawn 3 paths - one up, one right and one diagonally
:.z.s[x-1;y] + .z.s[x;y-1] + .z.s[x-1;y-1]
}
q)f[2;2]
3
q)f[2;3]
5
q)f[3;3]
13
If you are travelling along the edges and not the squares you can change the first line to:
if[any 0=(x;y);:1];
A closed form solution is just finding the Delannoy Number, which could be implemented something like this when you are travelling along edges.
d:{
k:1+min(x;y);
f:{prd 1+til x};
comb:{[f;m;n] f[m] div f[n]*f[m-n]}[f];
(sum/) (2 xexp til k) * prd (x;y) comb/:\: til k
}
q)d[3;3]
63f
This is much quicker for larger boards as I think the complexity of the first solution is O(3^m+n) while the complexity of the second is O(m*n)
q)\t f[7;7]
13
q)\t f[10;10]
1924
q)\t d[7;7]
0
q)\t d[100;100]
1

CSV import, only one column (Matlab/Octave)

I have since several days problems with reading my measurement csv files and make some simple calculations. I hope someone can help me.
My Aim
Read CSV data file, as followed:
Open with Excel:
date: 20140202 time: 083736 Cycles total: 74127 T_zer: 56 T_op1: 90.000
Actu state: stoppes ! T1: -23 T2: -12 T3: -32 T4: -65
*-*
324203 0 34724 0 0 0 2
431040 0 0 0 0 0 1
230706 0 0 0 0 0 1
340810 0 0 0 0 0 1
..............
....
.
-->Here 1st question: If I open with editor, I can only see one delimiter, its ";". But there must be two? One for row , one for columns? How can Excel separate it correctly into row and col, if there is only ";" ?
However... now I tried to csvread this file with octave. There I get it into octave, but everything only in one column:/. For me it would be very comfortable Octave could read it into a 7x X Matrix. In this case I can handle the data easy.
Here my Code:
clc
clear all
[fname,pname] =uigetfile();
fname;
extra="/";
pname;
b=strcat(pname,extra,fname);
m = csvread(b);
Result:
m as double with 4003x1. 4003 is corretct, but everything in one colum:/
m =
0
0
0
454203
561040
340706
I tried now to handle this problem up to several days, but no result.
Not a Octave expert, but looks like you can use the dlmread function to read a CSV files, it has many parameters which can help you read the file correctly.
start reading the data from row X (and not from the start)
only have Y columns
defined the separator between fields

Creating open-high-low-close (ohlc) bars from tick data in Matlab

I have a CSV file 'XPQ12.csv' of futures tick data in the following form:
20090312 30:14.0 717.25 1 E
20090312 30:15.0 718.47 1 E
20090312 30:17.0 717.25 1 E
20090312 30:32.0 718.42 1 E
20090312 30:49.0 715.32 1 E
20090312 30:58.0 717.57 1 E
20090312 31:06.0 716.65 3 E
20090312 31:12.0 718.35 2 E
20090312 31:45.0 721.14 1 E
20090312 31:52.0 719.24 1 E
20090312 32:11.0 717.02 6 E
20090312 32:29.0 717.14 1 E
20090312 32:35.0 717.34 1 E
20090312 32:55.0 717.26 1 E
(The first column is the yearmonthdate, the second column is the minute:second:tenthofsecond, the third column is the price, the fourth column is the number of contracts traded, and the fifth indicates if the trade was electronic or in a pit). In my actual data set, I may have thousands of price quotes within any given minute.
I read the file using the following code:
fid = fopen('C:\Program Files\MATLAB\R2013a\XPQ12.csv','r');
[c] = fscanf(fid, '%d,%d:%d.%d,%f,%d,%c')
Which outputs:
20090312
30
14
0
717.25
1
69
20090312
30
15
0
718.47
3
69
.
.
.
(the 69s are the matlab representation for E I believe)
Now I want to cut this up into one minute ohlc bars, so that for each minute, I record what the first, highest, lowest, and last price was within that minute. I'd really like to know the best way to go about this.
My original idea was to store the sequence of minutes in a vector d, and while working through the data, each time the number at the end of d changed I would record the corresponding price as an open, record the previous price as a close for the last bar, and find the largest and smallest prices within each open and close.
c(2) is the first minute, so I said:
d(1)=c(2);
and then noting that I'd always be counting by 7 before getting to the next minute, I said:
Nrows = numel(textread('XPQ12.csv','%1c%*[^\n]')); % counts rows in file
for i=1:Nrows
if mod(i-2,7)== 0;
d(end+1)=c(i);
end
end
which should fill up d with all the minutes:
30
30
30
30
30
30
31
31
31
31
32
32
32
32
in the case of the example data. I'm kind of lost what to do from here, or if what I'm doing is on the right track.
From where you are:
Minutes = c(2:7:end);
MinuteValues=unique(Minutes);
Prices = c(5:7:end);
if (length(Prices)>length(Minutes))
Prices=Prices(1:length(Minutes));
elseif (length(Prices)<length(Minutes))
Minutes=Minutes(1:length(Prices));
OverflowValues=1+find(Minutes(2:end)==0 & Minutes(1:end-1)==59);
for v=length(OverflowValues):-1:1
Minutes(OverflowValues(v):end)=Minutes(OverflowValues(v):end)+60;
end
Highs=zeros(1,length(MinuteValues));
Lows=zeros(1,length(MinuteValues));
First=zeros(1,length(MinuteValues));
Last=zeros(1,length(MinuteValues));
for v=1:length(MinuteValues)
Highs(v) = max(Prices(Minutes==MinuteValues(v)));
Lows(v) = min(Prices(Minutes==MinuteValues(v)));
First(v) = Prices(find(Minutes==MinuteVales(v),1,'first'));
Last(v) = Prices(find(Minutes==MinuteVales(v),1,'last'));
end
Using textread would make this easier for you, as mentioned.
(If you are lost at this stage, I wouldn't find accumarray as mentioned in the comments is the best place to start!)
By the way, this is assuming that minutes increases above 60 and you don't have hours in there somewhere. Otherwise this won't work at all.

Insert a row between two known rows in Matlab

I have a set of data shown bellow:
flow Rate (L/min)
Speed(rpm) 1 1.25 1.5 1.75 2 2.25 2.5 2.77 ... 6
Pressure (Pa)
2000 15251.2 15232 15200 15168 15027.2 14912 14752 0 ... 0
2050 16000 15840 15808 15744 15680 15520 15488 15232 ... 0
2100 16384 16256 16217.6 16192 16128 16064 16032 15872 ... 0
2150 17088 17024 16992 16960 16928 16832 16704 16512 ... 0
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
4250 61120 60800 60768 60736 60672 60736 60608 60416 ... 56960
At a specific speed (from 2000-4250rpm) and flow rate (from 1-6 L/min) as shown there are different pressures.
1) i want to know how can i insert a new row in between two of these speeds for example if i have a speed of 2030rpm i want to be able to find in between which two values the 2030rpm is and insert a row on matlab
demonstration hown below:
2000 15251.2 15232 15200 15168 15027.2 14912 14752 0 ... 0
2030 0 0 0 0 0 0 0 0
2050 16000 15840 15808 15744 15680 15520 15488 15232 ... 0
2) my second problem is how can i interpolate between the two values below (where the zero is and get a value.
15232
0
16000
I really appreciate if any one can answer any of my questions preferably the first one so ic an actually get to the second step lol
Thank you so much
newmat = zeros(size(oldmat,1)+1,size(oldmat,2))
newmat(1:x) = oldmat(1:x)
newmat(x+2:end) = oldmat(x+1:end)
where oldmat, newmat are the old and new versions of your matrix and x+1 the index of the row of 0s inserted into newmat.
Then, supposing that you want linear interpolation, something like:
newmat(x+1,:) = newmat(x,:)+0.6*(newmat(x+2,:)-newmat(x,:))
I expect I've made some small errors, and this is quite specific to your example, if you have trouble fixing and generalising, update your question or comment.
Assuming the data is stored in a matrix called p, for automatically positioning the new row in correct sequence:
Append the new row at the end of p, then:
p = sortrows(p)
Following up on the comments, we have:
newrow = [2130, zeros(1,size(test,2)-1)]
p(size(p,1)+1,:) = newrow
p = sortrows(p)
(if 2130 is the first value of the new row.)
This may help you:
% Matrix dimensions
nCols = 10;
nRows = 8;
% Synthetic data
matrix = [ linspace(2000,4250,nRows)' , 2000*rand(nRows,nCols-1)];
matrix([2,4],2:end) = zeros(2,nCols-1); % where some rows are zeros (2 and 4 on this example)
matrix
matrix =
1.0e+03 *
2.0000 1.7810 1.3674 1.4983 0.7329 1.5439 1.5639 0.2246 0.8653 1.5379
2.3214 0 0 0 0 0 0 0 0 0
2.6429 1.4687 1.4454 1.4801 1.3701 0.7765 0.5881 0.5831 0.2195 0.5459
2.9643 0 0 0 0 0 0 0 0 0
3.2857 0.1458 0.2350 1.4699 1.5787 0.4579 1.0617 1.9288 0.3749 1.3466
3.6071 0.1771 1.2814 1.9412 0.7353 1.2839 0.1830 0.8650 0.5324 0.8591
3.9286 1.5967 0.6576 1.7339 0.4121 0.9690 0.8106 1.3895 1.5957 0.9035
4.2500 1.8860 1.3076 0.1725 0.1733 0.3037 0.2097 1.5162 0.9752 1.2197
If you just want to fill the rows whose elements from the second to the last columns are zeros with the average value of the previous and the next rows.
for i=2:nRows-1
if ( sum(matrix(i,2:end))==0 )
matrix(i,2:end) = mean( matrix([i-1,i+1],2:end) );
end
end
matrix
matrix =
1.0e+03 *
2.0000 1.7810 1.3674 1.4983 0.7329 1.5439 1.5639 0.2246 0.8653 1.5379
2.3214 1.6248 1.4064 1.4892 1.0515 1.1602 1.0760 0.4039 0.5424 1.0419
2.6429 1.4687 1.4454 1.4801 1.3701 0.7765 0.5881 0.5831 0.2195 0.5459
2.9643 0.8072 0.8402 1.4750 1.4744 0.6172 0.8249 1.2560 0.2972 0.9462
3.2857 0.1458 0.2350 1.4699 1.5787 0.4579 1.0617 1.9288 0.3749 1.3466
3.6071 0.1771 1.2814 1.9412 0.7353 1.2839 0.1830 0.8650 0.5324 0.8591
3.9286 1.5967 0.6576 1.7339 0.4121 0.9690 0.8106 1.3895 1.5957 0.9035
4.2500 1.8860 1.3076 0.1725 0.1733 0.3037 0.2097 1.5162 0.9752 1.2197
This code assumes that:
You want to fill rows were only the first column element is non-zero.
You want to replace the zeros with the average between previous and next rows values.
You only interpolate inner rows.
I hope it helps.