Hi;
I am new to programming. I want to make a sliding window through colomns to claculate its average. For example
A B C D E F
2 4 5 6 9 0
4 5 6 6 6 7
5 3 4 4 4 4
7 7 7 8 8 8
if I have afile arranged in a similar way and way to calculate the average of each 2 rows for each individual, then slide one row below this. How can I do this.
Thanks for your help,
Ruby
11 4448 KevinADC 4,059
Recognized Expert Specialist
What have you tried so far? Anything? Whats a sliding window?
I mean I will read the file in perl as usual. I want to read each line then in the next line I will add the next value in the column the previous. in the previous example I want to know (2+4)/2 , (4+5)/2,...till the end of the row.
In the next row, I want to know (4+5)/2, (5+3)/2, (6+4)/2,....
I am in deep need for any help,
thanks
KevinADC 4,059
Recognized Expert Specialist
What have you tried so far?
miller 1,089
Recognized Expert Top Contributor
Hi epidemiologist,
What you describe does not sound hard. It sounds like a very simple programming logic challenge. However, as Kevin asks, what have you tried so far?
You say that you will read the file in perl "as usual". Well, start there. Show us the code where you read in the file and start processing the data.
Regards,
- Miller
Hi Miller,
I read the file like this: - open(INPUT, "< x.txt") or die "open INPUT: $!" ;
-
-
open (OUTPUT , "> y.txt") or die "open IOUTPUT: $!" ;;
-
-
while(defined(my $line=<INPUT>))
-
{
-
chomp($line);
-
my @matrix = split("\t", $line);
-
#I need here to insert the other part of the code to read the values, store it and #then add the next value in the same colum and print the the average on #another file
-
#e.g
-
print OUTPUT ("I am supposed to print the average as being calculated"; "\t";"the othe individ average"; "\n");
-
-
-
-
}
-
-
close (INPUT) or die "close INPUT: $!";
-
close (OUTPUT) or die "close OUTPUT: $!";
-
-
#################################
-
##this code should do this in a horizontal way while reading the file, I do not ##know what to do use the window size in avertical way
-
-
my $winsize = 7;
-
for(my $i = 1; $i <= $len-($winsize-1)); $i++) {
-
my $window = $seqobj->subseq($i,$i+($winsize-1));
-
}
-
I hope you could help me (this is not easy for me)
Thanks
KevinADC 4,059
Recognized Expert Specialist
one way to do it: - use strict;
-
use warnings;
-
use Data::Dumper;
-
my @AoA = ();
-
my $i = 0;
-
open(INPUT, "< x.txt") or die "open INPUT: $!";
-
open (OUTPUT , "> y.txt") or die "open IOUTPUT: $!";
-
-
# generate an array of arrays
-
while (<INPUT>) {
-
chomp;
-
push @{$AoA[$i]},split(/\s+/);
-
$i++;
-
}
-
-
# next line is for debugging uncomment to see the data structure
-
# print Dumper \@AoA;
-
-
# loop through the array of arrays and do the math and print to OUTPUT
-
foreach my $x (0..$#AoA-1) {
-
foreach my $y (0..$#{$AoA[$x]}) {
-
print OUTPUT +($AoA[$x][$y]+$AoA[$x+1][$y])/2,"\t";
-
}
-
print OUTPUT "\n";
-
}
-
reference material: Manipulating Arrays of Arrays in perl print function
I hope I am not doing your school/class work for you. I consider that cheating and unethical, I hope you do too.
- foreach my $x (0..$#AoA-1) {
should be - foreach my $x (0..$#AoA) {
Greetz, Doc
one way to do it:
Hi Kevin,
Many thanks for your help.
Ruby
KevinADC 4,059
Recognized Expert Specialist - foreach my $x (0..$#AoA-1) {
should be - foreach my $x (0..$#AoA) {
Greetz, Doc
No, that's not correct in this case: $AoA[$x+1]
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Lance Kind |
last post by:
Given: A really big table whose contents I want to view by
"lazyloading" parts of it at a time. The entire database is too big
to load all at once.
Requirements:
My UI is a window that shows ten records at a time. It pages up and
down. Initialy it loads with the first ten entries. I push page down
and the next ten show up. I can back up and look at the previous ten.
Right now, I'm just shooting for readonly access.
|
by: Ryan |
last post by:
What I want to do is run tcpdump continuously in the background and dump
to a file. Then, while tcpdump is working, I'd like to grab arbitrary chunks
of the open dump file and parse pieces at the head of the file. After I'm
done parsing I'd like to delete them from the front of the file, creating
a sort of sliding window effect.
What would be the best way to do this?
-ryan
|
by: Lonewolf |
last post by:
Hi,
does anyone know of a way to do sliding window similar to WMP 9's
slider bar which can slide up when the mouse gets to the bottom of the
screen in fullscreen mode during playback. Basically I'm trying to
achieve the same effect in my directshow program done in C# via managed
assembly. I don't know of any control which can do this kind of sliding.
can anyone enlighten me ?
|
by: filia&sofia |
last post by:
Let me rephrase my question that hasn't been answered properly. I want
to read a file into n-bit chunks of data _extremely fast_, process the
chunks and finally write them back into a different file. The problem
is that usually people suggest algorithms that are slow.
I'm thinking that the possible algorithm should first read the file
into a buffer (in computer memory), which is large w.r.t. length of
the individiual chunk of bits....
|
by: Noob |
last post by:
Hello,
Consider the following scenario.
'A' produces data which are sent in "packets" to 'B'.
Each "packet" carries a sequence number, so that 'B' can
insert the packet in the "right place" in a sorted list.
The sequence number of the 1st packet is 0.
The sequence number of the 65536th packet is 65535.
The sequence number of the 65537th packet "wraps around" back to 0.
| |
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |