help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: deleting duplicities, diag, equidistant data


From: Robert A. Macy
Subject: Re: deleting duplicities, diag, equidistant data
Date: Mon, 28 Feb 2005 06:58:00 -0800

I use a litle program I wrote that "slides" along, either
the rows, or the columns.  

neither program changes the size of the matrix, and at the
edges the programs maintain the proper means so the plots
look good.  

smoothby3alongrows.m
smoothby3downcolumns.m

The programs are pretty "nondistorting" so you can run them
over and over on the same data set and all you get is
smoothing.  For example, six times looks close to a cosine
smoothing.  

[watch out ! email editor wrapped these line ! ]

smoothby3alongrows.m
*****
function [output]=smoothby3alongrows(input);

%       SMOOTHBY3ALONGROWS will smooth along each row not change
end points
%       [output]=smoothby3alongrows(input);
%       uses 1/4  1/2  1/4  with the end points 1/2  1/4


if (nargin<1)
  help  smoothby3alongrows;
  return;
endif

[rowsinput,columnsinput]=size(input);

if (columnsinput<4)
  errormsg="this program needs more than 4 columns to work
well"
  return;
endif

%       body of matrix
output(:,2:columnsinput-1)=input(:,1:columnsinput-2)/4+input(:,2:columnsinput-1)/2+input(:,3:columnsinput)/4;

%       end points  since 1/2 and 1/4 change the mean use 4/3 to
enhance the edges...
output(:,1)=4*(input(:,1)/2+input(:,2)/4)/3;
output(:,columnsinput)=4*(input(:,columnsinput)/2+input(:,columnsinput-1)/4)/3;

***
smoothby3downcolumns.m
* * * * * *
function [output]=smoothby3downcolumns(input);

%       SMOOTHBY3DOWNCOLUMNS will smooth down along each column
not change end points
%       [output]=smoothby3downcolumns(input);
%       uses 1/4  1/2  1/4  with the end points 4/3 * ( 1/2  1/4
)

if (nargin<1)
  help  smoothby3downcolumns;
  return;
endif

[rowsinput,columnsinput]=size(input);

if (rowsinput<4)
  errormsg="this program needs more than 4 rows to work
well"
  return;
endif

%       body of matrix
output(2:rowsinput-1,:)=input(1:rowsinput-2,:)/4+input(2:rowsinput-1,:)/2+input(3:rowsinput,:)/4;

%       end points  since 1/2 and 1/4 change the mean use 4/3 to
enhance the edges...
output(1,:)=4*(input(1,:)/2+input(2,:)/4)/3;
output(rowsinput,:)=4*(input(rowsinput,:)/2+input(rowsinput-1,:)/4)/3;

                  - Robert -

On Mon, 28 Feb 2005 09:03:19 +0100
 "Jiri Pachman" <address@hidden> wrote:
> thanks to all for answers to my previous questions
> 
> Hi everybody,
> I have this simple problem. During data manipulation I
> create two  (sometimes 3) columns of data. First contains
> x values the others are y,  y2 values. It sometimes
> happens that I get two values of y are for the  same
> value of x (around 5 couples in matrix of 200 lines).
> This makes  problems in further calculations. I tried
> gnuplot´s smoothing (smooth  spline) function and it
> works well, taking the duplicate values and making  y
> average for particular x. Unfortunately I do not know,
> how to extract  this data in numeric format from gnuplot.
> I was looking for something  similar in octave, but
> without luck. Is there something like this in  octave?
> 
> For now I am using the following script that finds the
> duplicate values  and deletes them, but I would prefer to
> average them. I also tried to work  with diagonal using
> matlabs diag function, but it seems to work quite
>  differently (that is why I use rather complicated way to
> change 1 on the  diagonal to 0).
> 
> x = G12;
> vel = rows(x);
> indexy = zeros(vel);
> for i = 1:vel
> ind = x(:,1) == x(i,1);
> indexy(:,i) = ind;
> diamat(i,i) = 1;
> endfor
> 
> #% -------- indexes of duplicate values -------------
> err = (indexy - diamat);
> max(err)
> 
> #%--------------------- adding err columns creating index
>  ---------
> ind = err(:,1);
> for k=1:vel-1
> ind = ind + err(:,k+1);
> G12_nove = x(~ind, :);
> endfor
> 
> I am also interested, if there is some elegant way how to
> create  equidistant data from nonequidistant data. I use
> polynomial fit and then I  calculate the new values in
> linspace or logspace depending on the need.
> 
> thanks for help
> 
> Jiri
> 
> 
> -- 
> ***************************************************
> Ing. Jiri Pachman
> Katedra teorie a technologie vybusnin
> Univerzita Pardubice
> Studentska 95
> 532 10 Pardubice
> 
> tel.:  +420-46-603-8018
> fax.: +420-46-603-8024
> ***************************************************



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]