From: Thomas S. <t.s...@fz...> - 2013-03-12 09:57:07
|
stibala <adam.stibal <at> gmail.com> writes: > > Hello, > I have a matrix data set, each column contains a curve and I have a function > fitted to each curve. > I need to plot the original curves minus the respective fitted function and > here comes the problem. > My wanted code with for loop is > p for [i=2:11] "data.txt" u 1:(column(i) - function>i<($1)) > so I can't imagine how to iterate through my functions numbered as the > corresponding columns in data. > It can be done without the loop simply > p "data.txt" u 1:($2 - function2($1)), "data.txt" u 1:($3 - function3($1)), > ... > but I would like to plot it within the loop because I have a lot of data. > All the functions are the same, but with different constants, for example > g2(x)=exp(a2*x+b2)+c2 and g3(x)=exp(a3*x+b3)+c3. > > Thank you for your help > > Adam Stíbal > > -- pass the loop variable as a second argument to the function and distinguish between the different loop steps using the ternary operator: (here: from 2 to 5) g(x,column)=\ column==2?exp(a2*x+b2)+c2:\ column==3?exp(a3*x+b3)+c3:\ column==4?exp(a4*x+b4)+c4:\ column==5?exp(a5*x+b5)+c5:\ 0/0 |