I have a problem in reading .asc file that with channel location information.
When I try to read it using the EEGLAB GUI:
Edit -> Channel locations -> Select .asc file -> OK
the EEGLAB told me that “Index at position 1 is out of array bounds (cannot exceed 177)”. And I found that 177 is the number of lines in the .asc file.
Has anyone encountered the similar problem?
I type "help readlocs" to get the list of available formats and find .asc is a definite format. My .asc file is exported from neuroscan. The contents of the file are as follows:
;SCAN 4.0 ASCII Channel Description File
;
;Line format:
;#<channel number> <label>
;or:
;<display page> <channel number> <pos x0> <pos y0> <pos x1> <pos y1>
;
;A semicolon at the first column indicates a comment.
;
#1 FP1
#2 FPZ
#3 FP2
#4 AF3
#5 AF4
#6 F7
#7 F5
#8 F3
#9 F1
#10 FZ
#11 F2
#12 F4
#13 F6
#14 F8
#15 FT7
#16 FC5
#17 FC3
#18 FC1
#19 FCZ
#20 FC2
#21 FC4
#22 FC6
#23 FT8
#24 T7
#25 C5
#26 C3
#27 C1
#28 CZ
#29 C2
#30 C4
#31 C6
#32 T8
#33 M1
#34 TP7
#35 CP5
#36 CP3
#37 CP1
#38 CPZ
#39 CP2
#40 CP4
#41 CP6
#42 TP8
#43 M2
#44 P7
#45 P5
#46 P3
#47 P1
#48 PZ
#49 P2
#50 P4
#51 P6
#52 P8
#53 PO7
#54 PO5
#55 PO3
#56 POZ
#57 PO4
#58 PO6
#59 PO8
#60 CB1
#61 O1
#62 OZ
#63 O2
#64 CB2
0 1 0.401 0.088 0.439 0.133
0 2 0.459 0.075 0.496 0.121
0 3 0.517 0.084 0.554 0.130
0 4 0.373 0.173 0.410 0.219
0 5 0.546 0.168 0.583 0.214
0 6 0.229 0.232 0.267 0.278
0 7 0.287 0.242 0.324 0.288
0 8 0.345 0.246 0.382 0.291
0 9 0.402 0.246 0.439 0.291
0 10 0.459 0.246 0.497 0.291
0 11 0.517 0.246 0.555 0.291
0 12 0.574 0.243 0.612 0.289
0 13 0.632 0.236 0.670 0.281
0 14 0.689 0.228 0.727 0.274
0 15 0.228 0.338 0.265 0.384
0 16 0.286 0.347 0.323 0.392
0 17 0.344 0.347 0.382 0.392
0 18 0.403 0.348 0.440 0.394
0 19 0.459 0.350 0.497 0.396
0 20 0.517 0.347 0.555 0.392
0 21 0.575 0.345 0.612 0.391
0 22 0.632 0.343 0.670 0.389
0 23 0.689 0.342 0.726 0.388
0 24 0.227 0.450 0.265 0.496
0 25 0.286 0.449 0.324 0.495
0 26 0.345 0.448 0.382 0.494
0 27 0.402 0.449 0.439 0.495
0 28 0.459 0.449 0.497 0.495
0 29 0.517 0.447 0.554 0.493
0 30 0.574 0.447 0.611 0.492
0 31 0.632 0.445 0.669 0.491
0 32 0.690 0.444 0.727 0.490
0 33 0.170 0.552 0.208 0.598
0 34 0.228 0.552 0.265 0.598
0 35 0.286 0.552 0.323 0.598
0 36 0.342 0.553 0.380 0.599
0 37 0.400 0.553 0.437 0.599
0 38 0.458 0.552 0.496 0.598
0 39 0.517 0.553 0.554 0.599
0 40 0.575 0.552 0.613 0.598
0 41 0.630 0.552 0.668 0.598
0 42 0.688 0.552 0.725 0.598
0 43 0.748 0.552 0.784 0.598
0 44 0.227 0.693 0.264 0.738
0 45 0.287 0.669 0.324 0.715
0 46 0.345 0.659 0.382 0.705
0 47 0.400 0.656 0.438 0.702
0 48 0.458 0.653 0.496 0.699
0 49 0.517 0.655 0.555 0.700
0 50 0.575 0.656 0.612 0.701
0 51 0.633 0.664 0.670 0.710
0 52 0.690 0.695 0.728 0.741
0 53 0.278 0.807 0.315 0.853
0 54 0.343 0.774 0.380 0.820
0 55 0.401 0.766 0.439 0.811
0 56 0.459 0.764 0.496 0.809
0 57 0.517 0.761 0.554 0.807
0 58 0.575 0.773 0.612 0.819
0 59 0.637 0.809 0.674 0.855
0 60 0.340 0.885 0.377 0.931
0 61 0.401 0.899 0.439 0.945
0 62 0.459 0.918 0.496 0.963
0 63 0.516 0.899 0.553 0.945
0 64 0.575 0.879 0.612 0.925
1 1 0.028 0.032 0.139 0.161
1 2 0.167 0.032 0.278 0.161
1 3 0.306 0.032 0.417 0.161
1 4 0.444 0.032 0.556 0.161
1 5 0.583 0.032 0.694 0.161
1 6 0.722 0.032 0.833 0.161
1 7 0.861 0.032 0.972 0.161
1 8 0.028 0.194 0.139 0.323
1 9 0.167 0.194 0.278 0.323
1 10 0.306 0.194 0.417 0.323
1 11 0.444 0.194 0.556 0.323
1 12 0.583 0.194 0.694 0.323
1 13 0.722 0.194 0.833 0.323
1 14 0.861 0.194 0.972 0.323
1 15 0.028 0.355 0.139 0.484
1 16 0.167 0.355 0.278 0.484
1 17 0.306 0.355 0.417 0.484
1 18 0.444 0.355 0.556 0.484
1 19 0.583 0.355 0.694 0.484
1 20 0.722 0.355 0.833 0.484
1 21 0.861 0.355 0.972 0.484
1 22 0.028 0.516 0.139 0.645
1 23 0.167 0.516 0.278 0.645
1 24 0.306 0.516 0.417 0.645
1 25 0.444 0.516 0.556 0.645
1 26 0.583 0.516 0.694 0.645
1 27 0.722 0.516 0.833 0.645
1 28 0.861 0.516 0.972 0.645
1 29 0.028 0.677 0.139 0.806
1 30 0.167 0.677 0.278 0.806
1 31 0.306 0.677 0.417 0.806
1 32 0.444 0.677 0.556 0.806
1 33 0.583 0.677 0.694 0.806
1 34 0.722 0.677 0.833 0.806
1 35 0.861 0.677 0.972 0.806
1 36 0.028 0.839 0.139 0.968
1 37 0.167 0.839 0.278 0.968
1 38 0.306 0.839 0.417 0.968
1 39 0.444 0.839 0.556 0.968
1 40 0.583 0.839 0.694 0.968
Related
I have a matrix with three columns
https://www.dropbox.com/s/jckdmg1p05v8lv7/y.mat?dl=0
i.e.
E1 E2 W
6 1464 0.36
6 1534 0.27
6 1585 0.27
8 1331 0.332
11 445 0.39
13 844 0.286
14 12 0.126
18 952 0.31
19 2376 0.32
20 394 0.22
20 399 0.22
20 589 0.22
21 321 0.22
21 1187 0.22
21 2509 0.22
22 1187 0.22
23 2235 0.22
24 2376 0.22
25 541 0.14
26 229 0.22
26 321 0.22
26 1187 0.22
26 2054 0.22
27 394 0.53
27 541 0.31
28 394 0.22
28 781 0.22
I used this condition
for k=1:size(y,1)
G(y(k,1),y(k,2))=true;
G(y(k,2),y(k,1))=true;
end
B=cellfun(#(x1) find(x1),num2cell(G,2),'un',0);
to extract links information like this:
1 394
2 2378
3 282
4 282
5 536
6 [1464,1534,1585]
7 2087
8 [394,399,1331]
9 1187
I need a third column contains the weight
e.i. {6,[1464,1534,1585],[0.36;0.27;0.27]}
I tried to use the above condition but I did not get the right values. Does anyone have idea how to do that ??
this is a possible soultion using accumarray:
a=[...
6 1464 0.36
6 1534 0.27
6 1585 0.27
8 1331 0.332
11 445 0.39
13 844 0.286
14 12 0.126
18 952 0.31
19 2376 0.32
20 394 0.22
20 399 0.22
20 589 0.22
21 321 0.22
21 1187 0.22
21 2509 0.22
22 1187 0.22
23 2235 0.22
24 2376 0.22
25 541 0.14
26 229 0.22
26 321 0.22
26 1187 0.22
26 2054 0.22
27 394 0.53
27 541 0.31
28 394 0.22
28 781 0.22];
% concatenate a with its copy, columns 1 and 2 swapped regarding symmetric relations
a = [a ; [fliplr(a(: , 1:2)) , a(: , 3) ]];
%create proper increasing indices for use in accumarray
[S SI] = sort(a(:,1));
S2=[0; (cumsum(diff(S)>0))];
idx = a(:,1);
idx(SI) = S2+1;
%gather elemets for each category
c1=accumarray([idx],a(:,1),[],#(x) {x(1)});
c2=accumarray([idx],a(:,2),[],#(x) {x});
c3=accumarray([idx],a(:,3),[],#(x) {x});
%concatenate columns
out=([c1 c2 c3]);
% your example
out(1,:)
I have a huge 1.1 GB File. It contains only 1 line and 1167889705 characters. I want to replace all the occurences of "LFENT" by "\nLFENT".
I am using
perl 5, version 18, subversion 1 (v5.18.1) built for x86_64-linux –
Perl Script
perl -ne 's/LFENT/\nLFENT/g; print;' queries.txt
Sample
22 serialization::archive 10 0 0 0 0 134477 0 0 0 9 LFENT_1_1 6 LFDOC1 20 documents/LFDOC1.xml 6 PERSON 12 barack obama 0 0 1 0 12 barack obama 0 0 6 LFDOC1 0 76 127 0.11599133 151 0.11042373 331 0.057491675 389 0.05621225 396 0.065223008 398 0.12416559 421 0.10331947 502 0.055213902 641 0.08908961 642 0.084330745 690 0.11456303 699 0.16876614 720 0.080576144 791 0.077269703 792 0.077503696 849 0.08224529 854 0.074629158 1028 0.11078026 1039 0.091981322 1300 0.070129424 1359 0.06072164 1390 0.05564769 1424 0.076605573 1461 0.15357952 1467 0.083702087 1583 0.069745384 1960 0.088143557 2118 0.064093992 2192 0.054430917 2304 0.089718938 2417 0.10173298 2436 0.069064997 2683 0.12296619 2700 0.068218805 2715 0.14005794 2786 0.084942013 3016 0.08474879 3113 0.083180025 3183 0.07413847 3202 0.081254445 3351 0.21241546 3587 0.061469007 3711 0.068944298 3949 0.10349752 5284 0.087500088 5775 0.092185706 5816 0.20625457 6320 0.11784423 6435 0.076852165 6794 0.094336778 6805 0.063363358 6946 0.11133534 7277 0.074097082 7588 0.12458359 7590 0.099151991 7629 0.28773388 7790 0.1194713 8137 0.11009126 8214 0.10754209 8889 0.12056628 9326 0.13841057 9701 0.25610805 9863 0.11877144 9908 0.11499001 10500 0.12205271 11917 0.11144774 12750 0.11285295 13453 0.13751692 19236 0.12948024 20390 0.12416928 20795 0.11188922 23777 0.13165452 23887 0.10065161 27644 0.1620737 73361 0.16295943 75521 0.17926371 9 LFENT_1_2 6 LFDOC1 20 documents/LFDOC1.xml 6 PERSON 5 obama 2 0 12 barack obama 5 obama 6 LFDOC1 0 76 127 0.11599133 151 0.11042373 331 0.057491675 389 0.05621225 396 0.065223008 398 0.12416559 421 0.10331947 502 0.055213902 641 0.08908961 642 0.084330745 690 0.11456303 699 0.16876614 720 0.080576144 791 0.077269703 792 0.077503696 849 0.08224529 854 0.074629158 1028 0.11078026 1039 0.091981322 1300 0.070129424 1359 0.06072164 1390 0.05564769 1424 0.076605573 1461 0.15357952 1467 0.083702087 1583 0.069745384 1960 0.088143557 2118 0.064093992 2192 0.054430917 2304 0.089718938 2417 0.10173298 2436 0.069064997 2683 0.12296619 2700 0.068218805 2715 0.14005794 2786 0.084942013 3016 0.08474879 3113 0.083180025 3183 0.07413847 3202 0.081254445 3351 0.21241546 3587 0.061469007 3711 0.068944298 3949 0.10349752 5284 0.087500088 5775 0.092185706 5816 0.20625457 6320 0.11784423 6435 0.076852165 6794 0.094336778 6805 0.063363358 6946 0.11133534 7277 0.074097082 7588 0.12458359 7590 0.099151991 7629 0.28773388 7790 0.1194713 8137 0.11009126 8214 0.10754209 8889 0.12056628 9326 0.13841057 9701 0.25610805 9863 0.11877144 9908 0.11499001 10500 0.12205271 11917 0.11144774 12750 0.11285295 13453 0.13751692 19236 0.12948024 20390 0.12416928 20795 0.11188922 23777 0.13165452 23887 0.10065161 27644 0.1620737 73361 0.16295943 75521 0.17926371 9 LFENT_1_3 6 LFDOC1 20 documents/LFDOC1.xml 4 MISC 8 american 1 0 8 american 6 LFDOC1 0 76 127 0.11599133 151 0.11042373 331 0.057491675 389 0.05621225 396 0.065223008 398 0.12416559 421 0.10331947 502 0.055213902 641 0.08908961 642 0.084330745 690 0.11456303 699 0.16876614 720 0.080576144 791 0.077269703 792 0.077503696 849 0.08224529 854 0.074629158 1028 0.11078026 1039 0.091981322 1300 0.070129424 1359 0.06072164 1390 0.05564769 1424 0.076605573 1461 0.15357952 1467 0.083702087 1583 0.069745384 1960 0.088143557 2118 0.064093992 2192 0.054430917 2304 0.089718938 2417 0.10173298 2436 0.069064997 2683 0.12296619 2700 0.068218805 2715 0.14005794 2786 0.084942013 3016 0.08474879 3113 0.083180025 3183 0.07413847 3202 0.081254445 3351 0.21241546 3587 0.061469007 3711 0.068944298 3949 0.10349752 5284 0.087500088 5775 0.092185706 5816 0.20625457 6320 0.11784423 6435 0.076852165 6794 0.094336778 6805 0.063363358 6946 0.11133534 7277 0.074097082 7588 0.12458359 7590 0.099151991 7629 0.28773388 7790 0.1194713 8137 0.11009126 8214 0.10754209 8889 0.12056628 9326 0.13841057 9701 0.25610805 9863 0.11877144 9908 0.11499001 10500 0.12205271 11917 0.11144774 12750 0.11285295 13453 0.13751692 19236
Problem
The script will work on the sample that I posted. But when I try it on the whole line I get the following error:
Substitution loop at -e line 1, <> line 1.
It is simplest to use LFENT as the record separator. That reduces the blocks to a more manageable size and ensures that there is no more than one LFENT to be replaced in each block
Command-line perl allows for setting the record separator with the -0 modifier, but the value of the parameter must be the code point in octal of a single character, and you can't specify a string. So here you have to set it once in a BEGIN block
Like this
perl -p -e'BEGIN{$/="LFENT"} s/LFENT/\nLFENT/'
output
22 serialization::archive 10 0 0 0 0 134477 0 0 0 9
LFENT_1_1 6 LFDOC1 20 documents/LFDOC1.xml 6 PERSON 12 barack obama 0 0 1 0 12 barack obama 0 0 6 LFDOC1 0 76 127 0.11599133 151 0.11042373 331 0.057491675 389 0.05621225 396 0.065223008 398 0.12416559 421 0.10331947 502 0.055213902 641 0.08908961 642 0.084330745 690 0.11456303 699 0.16876614 720 0.080576144 791 0.077269703 792 0.077503696 849 0.08224529 854 0.074629158 1028 0.11078026 1039 0.091981322 1300 0.070129424 1359 0.06072164 1390 0.05564769 1424 0.076605573 1461 0.15357952 1467 0.083702087 1583 0.069745384 1960 0.088143557 2118 0.064093992 2192 0.054430917 2304 0.089718938 2417 0.10173298 2436 0.069064997 2683 0.12296619 2700 0.068218805 2715 0.14005794 2786 0.084942013 3016 0.08474879 3113 0.083180025 3183 0.07413847 3202 0.081254445 3351 0.21241546 3587 0.061469007 3711 0.068944298 3949 0.10349752 5284 0.087500088 5775 0.092185706 5816 0.20625457 6320 0.11784423 6435 0.076852165 6794 0.094336778 6805 0.063363358 6946 0.11133534 7277 0.074097082 7588 0.12458359 7590 0.099151991 7629 0.28773388 7790 0.1194713 8137 0.11009126 8214 0.10754209 8889 0.12056628 9326 0.13841057 9701 0.25610805 9863 0.11877144 9908 0.11499001 10500 0.12205271 11917 0.11144774 12750 0.11285295 13453 0.13751692 19236 0.12948024 20390 0.12416928 20795 0.11188922 23777 0.13165452 23887 0.10065161 27644 0.1620737 73361 0.16295943 75521 0.17926371 9
LFENT_1_2 6 LFDOC1 20 documents/LFDOC1.xml 6 PERSON 5 obama 2 0 12 barack obama 5 obama 6 LFDOC1 0 76 127 0.11599133 151 0.11042373 331 0.057491675 389 0.05621225 396 0.065223008 398 0.12416559 421 0.10331947 502 0.055213902 641 0.08908961 642 0.084330745 690 0.11456303 699 0.16876614 720 0.080576144 791 0.077269703 792 0.077503696 849 0.08224529 854 0.074629158 1028 0.11078026 1039 0.091981322 1300 0.070129424 1359 0.06072164 1390 0.05564769 1424 0.076605573 1461 0.15357952 1467 0.083702087 1583 0.069745384 1960 0.088143557 2118 0.064093992 2192 0.054430917 2304 0.089718938 2417 0.10173298 2436 0.069064997 2683 0.12296619 2700 0.068218805 2715 0.14005794 2786 0.084942013 3016 0.08474879 3113 0.083180025 3183 0.07413847 3202 0.081254445 3351 0.21241546 3587 0.061469007 3711 0.068944298 3949 0.10349752 5284 0.087500088 5775 0.092185706 5816 0.20625457 6320 0.11784423 6435 0.076852165 6794 0.094336778 6805 0.063363358 6946 0.11133534 7277 0.074097082 7588 0.12458359 7590 0.099151991 7629 0.28773388 7790 0.1194713 8137 0.11009126 8214 0.10754209 8889 0.12056628 9326 0.13841057 9701 0.25610805 9863 0.11877144 9908 0.11499001 10500 0.12205271 11917 0.11144774 12750 0.11285295 13453 0.13751692 19236 0.12948024 20390 0.12416928 20795 0.11188922 23777 0.13165452 23887 0.10065161 27644 0.1620737 73361 0.16295943 75521 0.17926371 9
LFENT_1_3 6 LFDOC1 20 documents/LFDOC1.xml 4 MISC 8 american 1 0 8 american 6 LFDOC1 0 76 127 0.11599133 151 0.11042373 331 0.057491675 389 0.05621225 396 0.065223008 398 0.12416559 421 0.10331947 502 0.055213902 641 0.08908961 642 0.084330745 690 0.11456303 699 0.16876614 720 0.080576144 791 0.077269703 792 0.077503696 849 0.08224529 854 0.074629158 1028 0.11078026 1039 0.091981322 1300 0.070129424 1359 0.06072164 1390 0.05564769 1424 0.076605573 1461 0.15357952 1467 0.083702087 1583 0.069745384 1960 0.088143557 2118 0.064093992 2192 0.054430917 2304 0.089718938 2417 0.10173298 2436 0.069064997 2683 0.12296619 2700 0.068218805 2715 0.14005794 2786 0.084942013 3016 0.08474879 3113 0.083180025 3183 0.07413847 3202 0.081254445 3351 0.21241546 3587 0.061469007 3711 0.068944298 3949 0.10349752 5284 0.087500088 5775 0.092185706 5816 0.20625457 6320 0.11784423 6435 0.076852165 6794 0.094336778 6805 0.063363358 6946 0.11133534 7277 0.074097082 7588 0.12458359 7590 0.099151991 7629 0.28773388 7790 0.1194713 8137 0.11009126 8214 0.10754209 8889 0.12056628 9326 0.13841057 9701 0.25610805 9863 0.11877144 9908 0.11499001 10500 0.12205271 11917 0.11144774 12750 0.11285295 13453 0.13751692 19236[Finished in 0.2s]
By the way, it is unlikely to cause a problem but LFENT is always preceded by a space character in your example data. You may want to remove it by using s/\s*LFENT/\nLFENT for your substitution
And a look-ahead might be more appropriate too s/\s*(?=LFENT)/\n/ so that you don't have to remove and replace the unchanged part of the match
Try updating your perl to a more current version.
This was a known bug for a long time (fixed in v5.22.0): perl #123071: substitution loop issue with long strings
You can do so with the following commands (assuming you are on linux):
wget http://www.cpan.org/src/5.0/perl-5.22.1.tar.gz
tar -xzf perl-5.22.1.tar.gz
cd perl-5.22.1
./Configure -des -Dprefix=$HOME/localperl
make
make test
make install
Then test it by running $HOME/localperl/bin/perl -v and add it to your PATH using this: export PATH=$HOME/localperl/bin/:$PATH.
I'm trying to generate this figure shown below:
(source: noaa.gov)
The data that I am using to try and generate this figure can be found here data.
This is a subset of the data that I extracted:
d = [1950 1 0.56
1950 2 0.01
1950 3 -0.78
1950 4 0.65
1950 5 -0.50
1950 6 0.25
1950 7 -1.23
1950 8 -0.19
1950 9 0.39
1950 10 1.43
1950 11 -1.46
1950 12 -1.03
1951 1 -0.42
1951 2 0.35
1951 3 -1.47
1951 4 -0.38
1951 5 -0.50
1951 6 -1.35
1951 7 1.39
1951 8 -0.41
1951 9 -1.18
1951 10 2.54
1951 11 -0.54
1951 12 1.13
1952 1 0.57
1952 2 -1.38
1952 3 -1.97
1952 4 0.95
1952 5 -0.99
1952 6 -0.10
1952 7 -0.06
1952 8 -0.49
1952 9 -0.38
1952 10 -0.28
1952 11 -1.32
1952 12 -0.49
1953 1 -0.12
1953 2 -1.00
1953 3 -0.45
1953 4 -1.96
1953 5 -0.56
1953 6 1.41
1953 7 0.43
1953 8 -1.04
1953 9 -0.19
1953 10 1.95
1953 11 0.96
1953 12 -0.52
1954 1 -0.08
1954 2 0.40
1954 3 -1.27
1954 4 1.31
1954 5 -0.03
1954 6 0.06
1954 7 -0.57
1954 8 -2.57
1954 9 -0.28
1954 10 1.16
1954 11 0.29
1954 12 0.55
1955 1 -2.65
1955 2 -1.71
1955 3 -0.96
1955 4 -0.60
1955 5 -0.26
1955 6 -0.80
1955 7 1.78
1955 8 1.25
1955 9 0.46
1955 10 -1.09
1955 11 -1.49
1955 12 0.07
1956 1 -0.76
1956 2 -1.71
1956 3 -0.46
1956 4 -1.30
1956 5 2.10
1956 6 0.41
1956 7 -0.72
1956 8 -1.89
1956 9 0.38
1956 10 1.47
1956 11 0.40
1956 12 0.00
1957 1 0.71
1957 2 -0.32
1957 3 -1.73
1957 4 0.39
1957 5 -0.68
1957 6 -0.42
1957 7 -1.16
1957 8 -0.83
1957 9 -1.47
1957 10 1.95
1957 11 0.63
1957 12 0.02
1958 1 -1.14
1958 2 -1.64
1958 3 -2.46
1958 4 0.26
1958 5 -0.17
1958 6 -1.08
1958 7 -1.69
1958 8 -2.13
1958 9 0.08
1958 10 0.68
1958 11 1.59
1958 12 -0.74
1959 1 -1.52
1959 2 0.33
1959 3 -0.56
1959 4 0.25
1959 5 0.41
1959 6 0.71
1959 7 0.77
1959 8 -0.05
1959 9 1.00
1959 10 1.48
1959 11 0.30
1959 12 0.32
1960 1 -2.01
1960 2 -2.59
1960 3 -0.93
1960 4 1.33
1960 5 0.47
1960 6 0.10
1960 7 0.38
1960 8 -1.93
1960 9 0.53
1960 10 -1.37
1960 11 -0.67
1960 12 -0.03
1961 1 -0.03
1961 2 0.07
1961 3 0.17
1961 4 -1.83
1961 5 -0.28
1961 6 1.17
1961 7 -0.36
1961 8 1.03
1961 9 1.36
1961 10 1.07
1961 11 -0.79
1961 12 -1.46
1962 1 0.20
1962 2 0.18
1962 3 -2.99
1962 4 0.93
1962 5 -0.04
1962 6 0.47
1962 7 -2.43
1962 8 0.05
1962 9 -0.21
1962 10 0.96
1962 11 -0.38
1962 12 -1.31
1963 1 -2.98
1963 2 -1.53
1963 3 -0.85
1963 4 -1.61
1963 5 2.05
1963 6 -0.13
1963 7 -0.74
1963 8 -0.95
1963 9 1.89
1963 10 1.53
1963 11 -1.47
1963 12 -1.87
1964 1 -1.62
1964 2 -2.06
1964 3 -1.66
1964 4 0.25
1964 5 0.53
1964 6 1.61
1964 7 1.92
1964 8 -2.40
1964 9 0.34
1964 10 1.32
1964 11 -0.14
1964 12 -0.23
1965 1 -0.65
1965 2 -2.20
1965 3 -1.99
1965 4 0.64
1965 5 -0.52
1965 6 0.60
1965 7 0.35
1965 8 0.45
1965 9 0.51
1965 10 0.92
1965 11 -1.88
1965 12 1.18
1966 1 -2.54
1966 2 -2.02
1966 3 0.18
1966 4 -0.96
1966 5 0.25
1966 6 1.37
1966 7 0.35
1966 8 -2.39
1966 9 -0.29
1966 10 -0.23
1966 11 -0.18
1966 12 0.58];
I've tried the code below to generate the above plot:
time = datenum(d(:,1),d(:,2),repmat(15,size(d,1),1));
nao = d(:,3);
figure(1);
ax1 = subplot(211);
area(time(nao < 0),nao(nao < 0),'FaceColor',[86 180 233]/255,'EdgeColor','none');
hold on;
area(time(nao > 0),nao(nao > 0),'FaceColor','r','EdgeColor','none');
datetick('x','yyyy','keeplimits');
ax2 = subplot(212);
bar(time(nao < 0),nao(nao < 0),'FaceColor',[86 180 233]/255,'EdgeColor','none');
hold on;
bar(time(nao > 0),nao(nao > 0),'FaceColor','r','EdgeColor','none');
datetick('x','yyyy','keeplimits');
linkaxes([ax1 ax2], 'x');
However, the output is not the same as that shown in the original figure, granted that they have a three month moving average. Ideally, I would have something that looked half like each of the plots I generated. That is, an area plot but with only a red or blue color at any given time. The area function seems to show these to happen at the same time, which is not correct. Any advice on how to generate the attached figure would be appreciated.
Using areashade from MATLAB FileExchange, the following should produce what you need:
figure(2);
areashade(time, nao, 0, [86 180 233]/255, 'h')
areashade(time, nao, 0,'r','l')
datetick('x','yyyy','keeplimits');
I have a table
WEEK_ID WEEK_STARTDATE WEEK_YEAR WEEK_MONTH WEEK_CREATEDTS
252 10/26/2008 2008 11 2008-10-07 15:10:00.000
253 11/02/2008 2008 11 2008-10-07 15:10:00.000
254 11/09/2008 2008 11 2008-10-07 15:10:00.000
255 11/16/2008 2008 11 2008-10-07 15:10:00.000
256 11/23/2008 2008 12 2008-10-07 15:10:00.000
257 11/30/2008 2008 12 2008-10-07 15:10:00.000
258 12/07/2008 2008 12 2008-10-07 15:10:00.000
259 12/14/2008 2008 12 2008-10-07 15:10:00.000
260 12/21/2008 2008 12 2008-10-07 15:10:00.000
266 2/1/2009 2009 2 2008-10-07 15:16:00.000
267 02/08/2009 2009 2 2008-10-07 15:16:00.000
268 02/15/2009 2009 2 2008-10-07 15:16:00.000
269 02/22/2009 2009 2 2008-10-07 15:16:00.000
270 3/1/2009 2009 3 2008-10-07 15:17:00.000
271 03/08/2009 2009 3 2008-10-07 15:17:00.000
272 03/15/2009 2009 3 2008-10-07 15:17:00.000
273 03/22/2009 2009 3 2008-10-07 15:17:00.000
274 3/29/2009 2009 4 2008-10-07 15:19:00.000
275 04/05/2009 2009 4 2008-10-07 15:19:00.000
276 04/12/2009 2009 4 2008-10-07 15:19:00.000
277 04/19/2009 2009 4 2008-10-07 15:19:00.000
278 04/26/2009 2009 4 2008-10-07 15:19:00.000
279 5/3/2009 2009 5 2008-10-07 15:20:00.000
280 05/10/2009 2009 5 2008-10-07 15:20:00.000
281 05/17/2009 2009 5 2008-10-07 15:20:00.000
282 05/24/2009 2009 5 2008-10-07 15:20:00.000
283 5/31/2009 2009 6 2008-10-07 15:34:00.000
284 06/07/2009 2009 6 2008-10-07 15:34:00.000
285 06/14/2009 2009 6 2008-10-07 15:34:00.000
286 06/21/2009 2009 6 2008-10-07 15:34:00.000
287 6/28/2009 2009 7 2008-10-07 15:36:00.000
288 07/05/2009 2009 7 2008-10-07 15:36:00.000
289 07/12/2009 2009 7 2008-10-07 15:36:00.000
290 07/19/2009 2009 7 2008-10-07 15:36:00.000
291 07/26/2009 2009 7 2008-10-07 15:36:00.000
297 12/28/2008 2009 1 2008-10-08 03:45:00.000
298 01/04/2009 2009 1 2008-10-08 03:45:00.000
299 01/11/2009 2009 1 2008-10-08 03:45:00.000
300 01/18/2009 2009 1 2008-10-08 03:45:00.000
301 01/25/2009 2009 1 2008-10-08 03:45:00.000
302 8/2/2009 2009 8 2008-10-28 12:52:00.000
303 08/09/2009 2009 8 2008-10-28 12:52:00.000
304 08/16/2009 2009 8 2008-10-28 12:52:00.000
305 08/23/2009 2009 8 2008-10-28 12:52:00.000
306 8/30/2009 2009 9 2008-10-28 12:54:00.000
307 09/06/2009 2009 9 2008-10-28 12:54:00.000
308 09/13/2009 2009 9 2008-10-28 12:54:00.000
309 09/20/2009 2009 9 2008-10-28 12:54:00.000
310 9/27/2009 2009 10 2008-10-28 12:54:00.000
311 10/04/2009 2009 10 2008-10-28 12:54:00.000
312 10/11/2009 2009 10 2008-10-28 12:54:00.000
313 10/18/2009 2009 10 2008-10-28 12:54:00.000
314 10/25/2009 2009 10 2008-10-28 12:54:00.000
315 11/1/2009 2009 11 2008-10-28 12:55:00.000
316 11/08/2009 2009 11 2008-10-28 12:55:00.000
317 11/15/2009 2009 11 2008-10-28 12:55:00.000
318 11/22/2009 2009 11 2008-10-28 12:55:00.000
319 11/29/2009 2009 12 2008-10-28 12:55:00.000
320 12/06/2009 2009 12 2008-10-28 12:55:00.000
321 12/13/2009 2009 12 2008-10-28 12:55:00.000
322 12/20/2009 2009 12 2008-10-28 12:55:00.000
323 12/28/2009 2010 1 2008-10-28 12:56:00.000
324 01/04/2010 2010 1 2008-10-28 12:56:00.000
325 01/11/2010 2010 1 2008-10-28 12:56:00.000
326 01/18/2010 2010 1 2008-10-28 12:56:00.000
327 01/25/2010 2010 1 2008-10-28 12:56:00.000
329 02/01/2010 2010 2 2010-01-18 08:10:00.000
330 02/08/2010 2010 2 2010-01-18 08:10:00.000
331 02/15/2010 2010 2 2010-01-18 08:10:00.000
332 02/22/2010 2010 2 2010-01-18 08:10:00.000
333 03/01/2010 2010 3 2010-01-18 08:11:00.000
334 03/08/2010 2010 3 2010-01-18 08:11:00.000
335 03/15/2010 2010 3 2010-01-18 08:11:00.000
336 03/22/2010 2010 3 2010-01-18 08:11:00.000
337 03/29/2010 2010 4 2010-03-17 11:00:00.000
338 04/05/2010 2010 4 2010-03-17 11:00:00.000
339 04/12/2010 2010 4 2010-03-17 11:00:00.000
340 04/19/2010 2010 4 2010-03-17 11:00:00.000
341 04/26/2010 2010 4 2010-03-17 11:00:00.000
342 05/03/2010 2010 5 2010-03-17 11:01:00.000
343 05/10/2010 2010 5 2010-03-17 11:01:00.000
344 05/17/2010 2010 5 2010-03-17 11:01:00.000
345 05/24/2010 2010 5 2010-03-17 11:01:00.000
346 05/31/2010 2010 6 2010-03-17 11:03:00.000
347 06/07/2010 2010 6 2010-03-17 11:03:00.000
348 06/14/2010 2010 6 2010-03-17 11:03:00.000
349 06/21/2010 2010 6 2010-03-17 11:03:00.000
350 06/28/2010 2010 7 2010-03-17 11:03:00.000
351 07/05/2010 2010 7 2010-03-17 11:03:00.000
352 07/12/2010 2010 7 2010-03-17 11:03:00.000
353 07/19/2010 2010 7 2010-03-17 11:03:00.000
354 07/26/2010 2010 7 2010-03-17 11:03:00.000
355 08/02/2010 2010 8 2010-03-17 11:04:00.000
356 08/09/2010 2010 8 2010-03-17 11:04:00.000
357 08/16/2010 2010 8 2010-03-17 11:04:00.000
358 08/23/2010 2010 8 2010-03-17 11:04:00.000
359 08/30/2010 2010 9 2010-03-17 11:05:00.000
360 09/06/2010 2010 9 2010-03-17 11:05:00.000
361 09/13/2010 2010 9 2010-03-17 11:05:00.000
362 09/20/2010 2010 9 2010-03-17 11:05:00.000
363 09/27/2010 2010 10 2010-03-17 11:06:00.000
364 10/04/2010 2010 10 2010-03-17 11:06:00.000
365 10/11/2010 2010 10 2010-03-17 11:06:00.000
366 10/18/2010 2010 10 2010-03-17 11:06:00.000
367 10/25/2010 2010 10 2010-03-17 11:06:00.000
368 11/01/2010 2010 11 2010-03-17 11:09:00.000
369 11/08/2010 2010 11 2010-03-17 11:09:00.000
370 11/15/2010 2010 11 2010-03-17 11:09:00.000
371 11/22/2010 2010 11 2010-03-17 11:09:00.000
372 11/29/2010 2010 12 2010-03-17 11:10:00.000
373 12/06/2010 2010 12 2010-03-17 11:10:00.000
374 12/13/2010 2010 12 2010-03-17 11:10:00.000
375 12/20/2010 2010 12 2010-03-17 11:10:00.000
376 12/27/2010 2011 1 2010-03-17 11:11:00.000
377 01/03/2011 2011 1 2010-03-17 11:11:00.000
378 01/10/2011 2011 1 2010-03-17 11:11:00.000
379 01/17/2011 2011 1 2010-03-17 11:11:00.000
380 01/24/2011 2011 1 2010-03-17 11:11:00.000
381 01/31/2011 2011 2 NULL
382 02/07/2011 2011 2 NULL
383 02/14/2011 2011 2 NULL
384 02/21/2011 2011 2 NULL
441 02/28/2011 2011 3 NULL
442 03/07/2011 2011 3 NULL
443 03/14/2011 2011 3 NULL
444 03/21/2011 2011 3 NULL
451 03/28/2011 2011 4 NULL
452 04/04/2011 2011 4 NULL
453 04/11/2011 2011 4 NULL
454 04/18/2011 2011 4 NULL
455 04/25/2011 2011 4 NULL
456 05/02/2011 2011 5 NULL
457 05/09/2011 2011 5 NULL
458 05/16/2011 2011 5 NULL
459 05/23/2011 2011 5 NULL
460 05/30/2011 2011 6 NULL
461 06/06/2011 2011 6 NULL
462 06/13/2011 2011 6 NULL
463 06/20/2011 2011 6 NULL
464 06/27/2011 2011 7 NULL
465 07/04/2011 2011 7 NULL
466 07/11/2011 2011 7 NULL
467 07/18/2011 2011 7 NULL
468 07/25/2011 2011 7 NULL
469 08/01/2011 2011 8 NULL
470 08/08/2011 2011 8 NULL
471 08/15/2011 2011 8 NULL
472 08/22/2011 2011 8 NULL
473 08/29/2011 2011 9 NULL
474 09/05/2011 2011 9 NULL
475 09/12/2011 2011 9 NULL
476 09/19/2011 2011 9 NULL
477 09/26/2011 2011 10 NULL
478 10/03/2011 2011 10 NULL
479 10/10/2011 2011 10 NULL
480 10/17/2011 2011 10 NULL
481 10/24/2011 2011 10 NULL
482 10/31/2011 2011 11 NULL
483 11/07/2011 2011 11 NULL
484 11/14/2011 2011 11 NULL
485 11/21/2011 2011 11 NULL
486 11/28/2011 2011 12 NULL
487 12/05/2011 2011 12 NULL
488 12/12/2011 2011 12 NULL
489 12/19/2011 2011 12 NULL
491 12/26/2011 2012 1 NULL
492 01/02/2012 2012 1 NULL
493 01/09/2012 2012 1 NULL
494 01/16/2012 2012 1 NULL
495 01/23/2012 2012 1 NULL
496 01/30/2012 2012 2 NULL
497 02/06/2012 2012 2 NULL
498 02/13/2012 2012 2 NULL
499 02/20/2012 2012 2 NULL
500 02/27/2012 2012 3 NULL
501 03/05/2012 2012 3 NULL
502 03/12/2012 2012 3 NULL
503 03/19/2012 2012 3 NULL
504 03/26/2012 2012 4 NULL
505 04/02/2012 2012 4 NULL
506 04/09/2012 2012 4 NULL
507 04/16/2012 2012 4 NULL
508 04/23/2012 2012 4 NULL
509 04/30/2012 2012 5 NULL
510 05/07/2012 2012 5 NULL
511 05/14/2012 2012 5 NULL
512 05/21/2012 2012 5 NULL
513 05/28/2012 2012 6 NULL
514 06/04/2012 2012 6 NULL
515 06/11/2012 2012 6 NULL
516 06/18/2012 2012 6 NULL
517 06/25/2012 2012 7 NULL
518 07/02/2012 2012 7 NULL
519 07/09/2012 2012 7 NULL
520 07/16/2012 2012 7 NULL
521 07/23/2012 2012 7 NULL
522 07/30/2012 2012 8 NULL
523 08/06/2012 2012 8 NULL
524 08/13/2012 2012 8 NULL
525 08/20/2012 2012 8 NULL
526 08/27/2012 2012 9 NULL
527 09/03/2012 2012 9 NULL
528 09/10/2012 2012 9 NULL
529 09/17/2012 2012 9 NULL
530 09/24/2012 2012 10 NULL
531 10/01/2012 2012 10 NULL
532 10/08/2012 2012 10 NULL
533 10/15/2012 2012 10 NULL
534 10/22/2012 2012 10 NULL
535 10/29/2012 2012 11 NULL
536 11/05/2012 2012 11 NULL
537 11/12/2012 2012 11 NULL
538 11/19/2012 2012 11 NULL
539 11/26/2012 2012 12 NULL
540 12/03/2012 2012 12 NULL
541 12/10/2012 2012 12 NULL
542 12/17/2012 2012 12 NULL
543 12/24/2012 2013 1 NULL
544 12/31/2012 2013 1 NULL
545 01/07/2013 2013 1 NULL
546 01/14/2013 2013 1 NULL
547 01/21/2013 2013 1 NULL
548 01/28/2012 2013 1 NULL
and I create a query by adding 7 days to week_startdate
select
week_id, week_startdate,
convert(varchar, dateadd(day, 7, week_startdate), 101) as week_enddate
from dbo.TBL_S3_FISCALWEEKS_1
and output of the above query is
week_id week_startdate week_enddate
252 10/26/2008 11/02/2008
253 11/02/2008 11/09/2008
254 11/09/2008 11/16/2008
255 11/16/2008 11/23/2008
256 11/23/2008 11/30/2008
257 11/30/2008 12/07/2008
258 12/07/2008 12/14/2008
259 12/14/2008 12/21/2008
260 12/21/2008 12/28/2008
266 2/1/2009 02/08/2009
267 02/08/2009 02/15/2009
268 02/15/2009 02/22/2009
269 02/22/2009 03/01/2009
270 3/1/2009 03/08/2009
271 03/08/2009 03/15/2009
272 03/15/2009 03/22/2009
273 03/22/2009 03/29/2009
274 3/29/2009 04/05/2009
275 04/05/2009 04/12/2009
276 04/12/2009 04/19/2009
277 04/19/2009 04/26/2009
278 04/26/2009 05/03/2009
279 5/3/2009 05/10/2009
280 05/10/2009 05/17/2009
281 05/17/2009 05/24/2009
282 05/24/2009 05/31/2009
283 5/31/2009 06/07/2009
284 06/07/2009 06/14/2009
285 06/14/2009 06/21/2009
286 06/21/2009 06/28/2009
287 6/28/2009 07/05/2009
288 07/05/2009 07/12/2009
289 07/12/2009 07/19/2009
290 07/19/2009 07/26/2009
291 07/26/2009 08/02/2009
297 12/28/2008 01/04/2009
298 01/04/2009 01/11/2009
299 01/11/2009 01/18/2009
300 01/18/2009 01/25/2009
301 01/25/2009 02/01/2009
302 8/2/2009 08/09/2009
303 08/09/2009 08/16/2009
304 08/16/2009 08/23/2009
305 08/23/2009 08/30/2009
306 8/30/2009 09/06/2009
307 09/06/2009 09/13/2009
308 09/13/2009 09/20/2009
309 09/20/2009 09/27/2009
310 9/27/2009 10/04/2009
311 10/04/2009 10/11/2009
312 10/11/2009 10/18/2009
313 10/18/2009 10/25/2009
314 10/25/2009 11/01/2009
315 11/1/2009 11/08/2009
316 11/08/2009 11/15/2009
317 11/15/2009 11/22/2009
318 11/22/2009 11/29/2009
319 11/29/2009 12/06/2009
320 12/06/2009 12/13/2009
321 12/13/2009 12/20/2009
322 12/20/2009 12/27/2009
323 12/28/2009 01/04/2010
324 01/04/2010 01/11/2010
325 01/11/2010 01/18/2010
326 01/18/2010 01/25/2010
327 01/25/2010 02/01/2010
329 02/01/2010 02/08/2010
330 02/08/2010 02/15/2010
331 02/15/2010 02/22/2010
332 02/22/2010 03/01/2010
333 03/01/2010 03/08/2010
334 03/08/2010 03/15/2010
335 03/15/2010 03/22/2010
336 03/22/2010 03/29/2010
337 03/29/2010 04/05/2010
338 04/05/2010 04/12/2010
339 04/12/2010 04/19/2010
340 04/19/2010 04/26/2010
341 04/26/2010 05/03/2010
342 05/03/2010 05/10/2010
343 05/10/2010 05/17/2010
344 05/17/2010 05/24/2010
345 05/24/2010 05/31/2010
346 05/31/2010 06/07/2010
347 06/07/2010 06/14/2010
348 06/14/2010 06/21/2010
349 06/21/2010 06/28/2010
350 06/28/2010 07/05/2010
351 07/05/2010 07/12/2010
352 07/12/2010 07/19/2010
353 07/19/2010 07/26/2010
354 07/26/2010 08/02/2010
355 08/02/2010 08/09/2010
356 08/09/2010 08/16/2010
357 08/16/2010 08/23/2010
358 08/23/2010 08/30/2010
359 08/30/2010 09/06/2010
360 09/06/2010 09/13/2010
361 09/13/2010 09/20/2010
362 09/20/2010 09/27/2010
363 09/27/2010 10/04/2010
364 10/04/2010 10/11/2010
365 10/11/2010 10/18/2010
366 10/18/2010 10/25/2010
367 10/25/2010 11/01/2010
368 11/01/2010 11/08/2010
369 11/08/2010 11/15/2010
370 11/15/2010 11/22/2010
371 11/22/2010 11/29/2010
372 11/29/2010 12/06/2010
373 12/06/2010 12/13/2010
374 12/13/2010 12/20/2010
375 12/20/2010 12/27/2010
376 12/27/2010 01/03/2011
377 01/03/2011 01/10/2011
378 01/10/2011 01/17/2011
379 01/17/2011 01/24/2011
380 01/24/2011 01/31/2011
381 01/31/2011 02/07/2011
382 02/07/2011 02/14/2011
383 02/14/2011 02/21/2011
384 02/21/2011 02/28/2011
441 02/28/2011 03/07/2011
442 03/07/2011 03/14/2011
443 03/14/2011 03/21/2011
444 03/21/2011 03/28/2011
451 03/28/2011 04/04/2011
452 04/04/2011 04/11/2011
453 04/11/2011 04/18/2011
454 04/18/2011 04/25/2011
455 04/25/2011 05/02/2011
456 05/02/2011 05/09/2011
457 05/09/2011 05/16/2011
458 05/16/2011 05/23/2011
459 05/23/2011 05/30/2011
460 05/30/2011 06/06/2011
461 06/06/2011 06/13/2011
462 06/13/2011 06/20/2011
463 06/20/2011 06/27/2011
464 06/27/2011 07/04/2011
465 07/04/2011 07/11/2011
466 07/11/2011 07/18/2011
467 07/18/2011 07/25/2011
468 07/25/2011 08/01/2011
469 08/01/2011 08/08/2011
470 08/08/2011 08/15/2011
471 08/15/2011 08/22/2011
472 08/22/2011 08/29/2011
473 08/29/2011 09/05/2011
474 09/05/2011 09/12/2011
475 09/12/2011 09/19/2011
476 09/19/2011 09/26/2011
477 09/26/2011 10/03/2011
478 10/03/2011 10/10/2011
479 10/10/2011 10/17/2011
480 10/17/2011 10/24/2011
481 10/24/2011 10/31/2011
482 10/31/2011 11/07/2011
483 11/07/2011 11/14/2011
484 11/14/2011 11/21/2011
485 11/21/2011 11/28/2011
486 11/28/2011 12/05/2011
487 12/05/2011 12/12/2011
488 12/12/2011 12/19/2011
489 12/19/2011 12/26/2011
491 12/26/2011 01/02/2012
492 01/02/2012 01/09/2012
493 01/09/2012 01/16/2012
494 01/16/2012 01/23/2012
495 01/23/2012 01/30/2012
496 01/30/2012 02/06/2012
497 02/06/2012 02/13/2012
498 02/13/2012 02/20/2012
499 02/20/2012 02/27/2012
500 02/27/2012 03/05/2012
501 03/05/2012 03/12/2012
502 03/12/2012 03/19/2012
503 03/19/2012 03/26/2012
504 03/26/2012 04/02/2012
505 04/02/2012 04/09/2012
506 04/09/2012 04/16/2012
507 04/16/2012 04/23/2012
508 04/23/2012 04/30/2012
509 04/30/2012 05/07/2012
510 05/07/2012 05/14/2012
511 05/14/2012 05/21/2012
512 05/21/2012 05/28/2012
513 05/28/2012 06/04/2012
514 06/04/2012 06/11/2012
515 06/11/2012 06/18/2012
516 06/18/2012 06/25/2012
517 06/25/2012 07/02/2012
518 07/02/2012 07/09/2012
519 07/09/2012 07/16/2012
520 07/16/2012 07/23/2012
521 07/23/2012 07/30/2012
522 07/30/2012 08/06/2012
523 08/06/2012 08/13/2012
524 08/13/2012 08/20/2012
525 08/20/2012 08/27/2012
526 08/27/2012 09/03/2012
527 09/03/2012 09/10/2012
528 09/10/2012 09/17/2012
529 09/17/2012 09/24/2012
530 09/24/2012 10/01/2012
531 10/01/2012 10/08/2012
532 10/08/2012 10/15/2012
533 10/15/2012 10/22/2012
534 10/22/2012 10/29/2012
535 10/29/2012 11/05/2012
536 11/05/2012 11/12/2012
537 11/12/2012 11/19/2012
538 11/19/2012 11/26/2012
539 11/26/2012 12/03/2012
540 12/03/2012 12/10/2012
541 12/10/2012 12/17/2012
542 12/17/2012 12/24/2012
543 12/24/2012 12/31/2012
544 12/31/2012 01/07/2013
545 01/07/2013 01/14/2013
546 01/14/2013 01/21/2013
547 01/21/2013 01/28/2013
548 01/28/2012 02/04/2012
The thing is I need to get week_ids between two days. I need it in function
or procedure would u please help me out as soon as possible
A simple SELECT WHERE BETWEEN should do the job for you. Pass in the two dates as parameters, and
SELECT week_id FROM TBL_S3_FISCALWEEKS_1
WHERE WeekStartDate BETWEEN #DateParam1 AND #DateParam2
This will work even if the exact date doesn't appear in WeekStartDate
So you want a query or function that returns the week_id if you feed it a date (even if it is a date that falls between your week_startdate and week_enddate), right?
You might want to try something like the following query:
SELECT week_id
FROM weeks
WHERE DATEDIFF(dd, week_startdate, input_date) < 7
AND DATEDIFF(dd, week_startdate, input_date) > 0
Check the MSDN DATEDIFF reference for more information on DATEDIFF.
Help me,
i have a table like this
WEEK_ID WEEK_STARTDATE WEEK_YEAR WEEK_MONTH WEEK_CREATEDTS
------------------------------------------------------------------------
252 10/26/2008 2008 11 2008-10-07 15:10:00.000
253 11/02/2008 2008 11 2008-10-07 15:10:00.000
254 11/09/2008 2008 11 2008-10-07 15:10:00.000
255 11/16/2008 2008 11 2008-10-07 15:10:00.000
256 11/23/2008 2008 12 2008-10-07 15:10:00.000
257 11/30/2008 2008 12 2008-10-07 15:10:00.000
258 12/07/2008 2008 12 2008-10-07 15:10:00.000
259 12/14/2008 2008 12 2008-10-07 15:10:00.000
260 12/21/2008 2008 12 2008-10-07 15:10:00.000
266 2/1/2009 2009 2 2008-10-07 15:16:00.000
267 02/08/2009 2009 2 2008-10-07 15:16:00.000
268 02/15/2009 2009 2 2008-10-07 15:16:00.000
269 02/22/2009 2009 2 2008-10-07 15:16:00.000
270 3/1/2009 2009 3 2008-10-07 15:17:00.000
271 03/08/2009 2009 3 2008-10-07 15:17:00.000
272 03/15/2009 2009 3 2008-10-07 15:17:00.000
273 03/22/2009 2009 3 2008-10-07 15:17:00.000
274 3/29/2009 2009 4 2008-10-07 15:19:00.000
275 04/05/2009 2009 4 2008-10-07 15:19:00.000
276 04/12/2009 2009 4 2008-10-07 15:19:00.000
277 04/19/2009 2009 4 2008-10-07 15:19:00.000
278 04/26/2009 2009 4 2008-10-07 15:19:00.000
279 5/3/2009 2009 5 2008-10-07 15:20:00.000
280 05/10/2009 2009 5 2008-10-07 15:20:00.000
281 05/17/2009 2009 5 2008-10-07 15:20:00.000
282 05/24/2009 2009 5 2008-10-07 15:20:00.000
283 5/31/2009 2009 6 2008-10-07 15:34:00.000
284 06/07/2009 2009 6 2008-10-07 15:34:00.000
285 06/14/2009 2009 6 2008-10-07 15:34:00.000
286 06/21/2009 2009 6 2008-10-07 15:34:00.000
287 6/28/2009 2009 7 2008-10-07 15:36:00.000
288 07/05/2009 2009 7 2008-10-07 15:36:00.000
289 07/12/2009 2009 7 2008-10-07 15:36:00.000
290 07/19/2009 2009 7 2008-10-07 15:36:00.000
291 07/26/2009 2009 7 2008-10-07 15:36:00.000
297 12/28/2008 2009 1 2008-10-08 03:45:00.000
298 01/04/2009 2009 1 2008-10-08 03:45:00.000
299 01/11/2009 2009 1 2008-10-08 03:45:00.000
300 01/18/2009 2009 1 2008-10-08 03:45:00.000
301 01/25/2009 2009 1 2008-10-08 03:45:00.000
302 8/2/2009 2009 8 2008-10-28 12:52:00.000
303 08/09/2009 2009 8 2008-10-28 12:52:00.000
304 08/16/2009 2009 8 2008-10-28 12:52:00.000
305 08/23/2009 2009 8 2008-10-28 12:52:00.000
306 8/30/2009 2009 9 2008-10-28 12:54:00.000
307 09/06/2009 2009 9 2008-10-28 12:54:00.000
308 09/13/2009 2009 9 2008-10-28 12:54:00.000
309 09/20/2009 2009 9 2008-10-28 12:54:00.000
310 9/27/2009 2009 10 2008-10-28 12:54:00.000
311 10/04/2009 2009 10 2008-10-28 12:54:00.000
312 10/11/2009 2009 10 2008-10-28 12:54:00.000
313 10/18/2009 2009 10 2008-10-28 12:54:00.000
314 10/25/2009 2009 10 2008-10-28 12:54:00.000
315 11/1/2009 2009 11 2008-10-28 12:55:00.000
316 11/08/2009 2009 11 2008-10-28 12:55:00.000
317 11/15/2009 2009 11 2008-10-28 12:55:00.000
318 11/22/2009 2009 11 2008-10-28 12:55:00.000
319 11/29/2009 2009 12 2008-10-28 12:55:00.000
320 12/06/2009 2009 12 2008-10-28 12:55:00.000
321 12/13/2009 2009 12 2008-10-28 12:55:00.000
322 12/20/2009 2009 12 2008-10-28 12:55:00.000
323 12/28/2009 2010 1 2008-10-28 12:56:00.000
324 01/04/2010 2010 1 2008-10-28 12:56:00.000
325 01/11/2010 2010 1 2008-10-28 12:56:00.000
326 01/18/2010 2010 1 2008-10-28 12:56:00.000
327 01/25/2010 2010 1 2008-10-28 12:56:00.000
329 02/01/2010 2010 2 2010-01-18 08:10:00.000
330 02/08/2010 2010 2 2010-01-18 08:10:00.000
331 02/15/2010 2010 2 2010-01-18 08:10:00.000
332 02/22/2010 2010 2 2010-01-18 08:10:00.000
333 03/01/2010 2010 3 2010-01-18 08:11:00.000
334 03/08/2010 2010 3 2010-01-18 08:11:00.000
335 03/15/2010 2010 3 2010-01-18 08:11:00.000
336 03/22/2010 2010 3 2010-01-18 08:11:00.000
337 03/29/2010 2010 4 2010-03-17 11:00:00.000
338 04/05/2010 2010 4 2010-03-17 11:00:00.000
339 04/12/2010 2010 4 2010-03-17 11:00:00.000
340 04/19/2010 2010 4 2010-03-17 11:00:00.000
341 04/26/2010 2010 4 2010-03-17 11:00:00.000
342 05/03/2010 2010 5 2010-03-17 11:01:00.000
343 05/10/2010 2010 5 2010-03-17 11:01:00.000
344 05/17/2010 2010 5 2010-03-17 11:01:00.000
345 05/24/2010 2010 5 2010-03-17 11:01:00.000
346 05/31/2010 2010 6 2010-03-17 11:03:00.000
347 06/07/2010 2010 6 2010-03-17 11:03:00.000
348 06/14/2010 2010 6 2010-03-17 11:03:00.000
349 06/21/2010 2010 6 2010-03-17 11:03:00.000
350 06/28/2010 2010 7 2010-03-17 11:03:00.000
351 07/05/2010 2010 7 2010-03-17 11:03:00.000
352 07/12/2010 2010 7 2010-03-17 11:03:00.000
353 07/19/2010 2010 7 2010-03-17 11:03:00.000
354 07/26/2010 2010 7 2010-03-17 11:03:00.000
355 08/02/2010 2010 8 2010-03-17 11:04:00.000
356 08/09/2010 2010 8 2010-03-17 11:04:00.000
357 08/16/2010 2010 8 2010-03-17 11:04:00.000
358 08/23/2010 2010 8 2010-03-17 11:04:00.000
359 08/30/2010 2010 9 2010-03-17 11:05:00.000
360 09/06/2010 2010 9 2010-03-17 11:05:00.000
361 09/13/2010 2010 9 2010-03-17 11:05:00.000
362 09/20/2010 2010 9 2010-03-17 11:05:00.000
363 09/27/2010 2010 10 2010-03-17 11:06:00.000
364 10/04/2010 2010 10 2010-03-17 11:06:00.000
365 10/11/2010 2010 10 2010-03-17 11:06:00.000
366 10/18/2010 2010 10 2010-03-17 11:06:00.000
367 10/25/2010 2010 10 2010-03-17 11:06:00.000
368 11/01/2010 2010 11 2010-03-17 11:09:00.000
369 11/08/2010 2010 11 2010-03-17 11:09:00.000
370 11/15/2010 2010 11 2010-03-17 11:09:00.000
371 11/22/2010 2010 11 2010-03-17 11:09:00.000
372 11/29/2010 2010 12 2010-03-17 11:10:00.000
373 12/06/2010 2010 12 2010-03-17 11:10:00.000
374 12/13/2010 2010 12 2010-03-17 11:10:00.000
375 12/20/2010 2010 12 2010-03-17 11:10:00.000
376 12/27/2010 2011 1 2010-03-17 11:11:00.000
377 01/03/2011 2011 1 2010-03-17 11:11:00.000
378 01/10/2011 2011 1 2010-03-17 11:11:00.000
379 01/17/2011 2011 1 2010-03-17 11:11:00.000
380 01/24/2011 2011 1 2010-03-17 11:11:00.000
381 01/31/2011 2011 2 NULL
382 02/07/2011 2011 2 NULL
383 02/14/2011 2011 2 NULL
384 02/21/2011 2011 2 NULL
441 02/28/2011 2011 3 NULL
442 03/07/2011 2011 3 NULL
443 03/14/2011 2011 3 NULL
444 03/21/2011 2011 3 NULL
451 03/28/2011 2011 4 NULL
452 04/04/2011 2011 4 NULL
453 04/11/2011 2011 4 NULL
454 04/18/2011 2011 4 NULL
455 04/25/2011 2011 4 NULL
456 05/02/2011 2011 5 NULL
457 05/09/2011 2011 5 NULL
458 05/16/2011 2011 5 NULL
459 05/23/2011 2011 5 NULL
460 05/30/2011 2011 6 NULL
461 06/06/2011 2011 6 NULL
462 06/13/2011 2011 6 NULL
463 06/20/2011 2011 6 NULL
464 06/27/2011 2011 7 NULL
465 07/04/2011 2011 7 NULL
466 07/11/2011 2011 7 NULL
467 07/18/2011 2011 7 NULL
468 07/25/2011 2011 7 NULL
469 08/01/2011 2011 8 NULL
470 08/08/2011 2011 8 NULL
471 08/15/2011 2011 8 NULL
472 08/22/2011 2011 8 NULL
473 08/29/2011 2011 9 NULL
474 09/05/2011 2011 9 NULL
475 09/12/2011 2011 9 NULL
476 09/19/2011 2011 9 NULL
477 09/26/2011 2011 10 NULL
478 10/03/2011 2011 10 NULL
479 10/10/2011 2011 10 NULL
480 10/17/2011 2011 10 NULL
481 10/24/2011 2011 10 NULL
482 10/31/2011 2011 11 NULL
483 11/07/2011 2011 11 NULL
484 11/14/2011 2011 11 NULL
485 11/21/2011 2011 11 NULL
486 11/28/2011 2011 12 NULL
487 12/05/2011 2011 12 NULL
488 12/12/2011 2011 12 NULL
489 12/19/2011 2011 12 NULL
491 12/26/2011 2012 1 NULL
492 01/02/2012 2012 1 NULL
493 01/09/2012 2012 1 NULL
494 01/16/2012 2012 1 NULL
495 01/23/2012 2012 1 NULL
496 01/30/2012 2012 2 NULL
497 02/06/2012 2012 2 NULL
498 02/13/2012 2012 2 NULL
499 02/20/2012 2012 2 NULL
500 02/27/2012 2012 3 NULL
501 03/05/2012 2012 3 NULL
502 03/12/2012 2012 3 NULL
503 03/19/2012 2012 3 NULL
504 03/26/2012 2012 4 NULL
505 04/02/2012 2012 4 NULL
506 04/09/2012 2012 4 NULL
507 04/16/2012 2012 4 NULL
508 04/23/2012 2012 4 NULL
509 04/30/2012 2012 5 NULL
510 05/07/2012 2012 5 NULL
511 05/14/2012 2012 5 NULL
512 05/21/2012 2012 5 NULL
513 05/28/2012 2012 6 NULL
514 06/04/2012 2012 6 NULL
515 06/11/2012 2012 6 NULL
516 06/18/2012 2012 6 NULL
517 06/25/2012 2012 7 NULL
518 07/02/2012 2012 7 NULL
519 07/09/2012 2012 7 NULL
520 07/16/2012 2012 7 NULL
521 07/23/2012 2012 7 NULL
522 07/30/2012 2012 8 NULL
523 08/06/2012 2012 8 NULL
524 08/13/2012 2012 8 NULL
525 08/20/2012 2012 8 NULL
526 08/27/2012 2012 9 NULL
527 09/03/2012 2012 9 NULL
528 09/10/2012 2012 9 NULL
529 09/17/2012 2012 9 NULL
530 09/24/2012 2012 10 NULL
531 10/01/2012 2012 10 NULL
532 10/08/2012 2012 10 NULL
533 10/15/2012 2012 10 NULL
534 10/22/2012 2012 10 NULL
535 10/29/2012 2012 11 NULL
536 11/05/2012 2012 11 NULL
537 11/12/2012 2012 11 NULL
538 11/19/2012 2012 11 NULL
539 11/26/2012 2012 12 NULL
540 12/03/2012 2012 12 NULL
541 12/10/2012 2012 12 NULL
542 12/17/2012 2012 12 NULL
543 12/24/2012 2013 1 NULL
544 12/31/2012 2013 1 NULL
545 01/07/2013 2013 1 NULL
546 01/14/2013 2013 1 NULL
547 01/21/2013 2013 1 NULL
548 01/28/2012 2013 1 NULL
I wrote a query to add 6 days to week_startdate like this
select week_id,week_startdate,convert(varchar,dateadd(day,6,week_startdate),101) as week_enddate from dbo.TBL_S3_FISCALWEEKS_1
and the result of the query is
week_id week_startdate week_enddate
252 10/26/2008 11/01/2008
253 11/02/2008 11/08/2008
254 11/09/2008 11/15/2008
255 11/16/2008 11/22/2008
256 11/23/2008 11/29/2008
257 11/30/2008 12/06/2008
258 12/07/2008 12/13/2008
259 12/14/2008 12/20/2008
260 12/21/2008 12/27/2008
266 2/1/2009 02/07/2009
267 02/08/2009 02/14/2009
268 02/15/2009 02/21/2009
269 02/22/2009 02/28/2009
270 3/1/2009 03/07/2009
271 03/08/2009 03/14/2009
272 03/15/2009 03/21/2009
273 03/22/2009 03/28/2009
274 3/29/2009 04/04/2009
275 04/05/2009 04/11/2009
276 04/12/2009 04/18/2009
277 04/19/2009 04/25/2009
278 04/26/2009 05/02/2009
279 5/3/2009 05/09/2009
280 05/10/2009 05/16/2009
281 05/17/2009 05/23/2009
282 05/24/2009 05/30/2009
283 5/31/2009 06/06/2009
284 06/07/2009 06/13/2009
285 06/14/2009 06/20/2009
286 06/21/2009 06/27/2009
287 6/28/2009 07/04/2009
288 07/05/2009 07/11/2009
289 07/12/2009 07/18/2009
290 07/19/2009 07/25/2009
291 07/26/2009 08/01/2009
297 12/28/2008 01/03/2009
298 01/04/2009 01/10/2009
299 01/11/2009 01/17/2009
300 01/18/2009 01/24/2009
301 01/25/2009 01/31/2009
302 8/2/2009 08/08/2009
303 08/09/2009 08/15/2009
304 08/16/2009 08/22/2009
305 08/23/2009 08/29/2009
306 8/30/2009 09/05/2009
307 09/06/2009 09/12/2009
308 09/13/2009 09/19/2009
309 09/20/2009 09/26/2009
310 9/27/2009 10/03/2009
311 10/04/2009 10/10/2009
312 10/11/2009 10/17/2009
313 10/18/2009 10/24/2009
314 10/25/2009 10/31/2009
315 11/1/2009 11/07/2009
316 11/08/2009 11/14/2009
317 11/15/2009 11/21/2009
318 11/22/2009 11/28/2009
319 11/29/2009 12/05/2009
320 12/06/2009 12/12/2009
321 12/13/2009 12/19/2009
322 12/20/2009 12/26/2009
323 12/28/2009 01/03/2010
324 01/04/2010 01/10/2010
325 01/11/2010 01/17/2010
326 01/18/2010 01/24/2010
327 01/25/2010 01/31/2010
329 02/01/2010 02/07/2010
330 02/08/2010 02/14/2010
331 02/15/2010 02/21/2010
332 02/22/2010 02/28/2010
333 03/01/2010 03/07/2010
334 03/08/2010 03/14/2010
335 03/15/2010 03/21/2010
336 03/22/2010 03/28/2010
337 03/29/2010 04/04/2010
338 04/05/2010 04/11/2010
339 04/12/2010 04/18/2010
340 04/19/2010 04/25/2010
341 04/26/2010 05/02/2010
342 05/03/2010 05/09/2010
343 05/10/2010 05/16/2010
344 05/17/2010 05/23/2010
345 05/24/2010 05/30/2010
346 05/31/2010 06/06/2010
347 06/07/2010 06/13/2010
348 06/14/2010 06/20/2010
349 06/21/2010 06/27/2010
350 06/28/2010 07/04/2010
351 07/05/2010 07/11/2010
352 07/12/2010 07/18/2010
353 07/19/2010 07/25/2010
354 07/26/2010 08/01/2010
355 08/02/2010 08/08/2010
356 08/09/2010 08/15/2010
357 08/16/2010 08/22/2010
358 08/23/2010 08/29/2010
359 08/30/2010 09/05/2010
360 09/06/2010 09/12/2010
361 09/13/2010 09/19/2010
362 09/20/2010 09/26/2010
363 09/27/2010 10/03/2010
364 10/04/2010 10/10/2010
365 10/11/2010 10/17/2010
366 10/18/2010 10/24/2010
367 10/25/2010 10/31/2010
368 11/01/2010 11/07/2010
369 11/08/2010 11/14/2010
370 11/15/2010 11/21/2010
371 11/22/2010 11/28/2010
372 11/29/2010 12/05/2010
373 12/06/2010 12/12/2010
374 12/13/2010 12/19/2010
375 12/20/2010 12/26/2010
376 12/27/2010 01/02/2011
377 01/03/2011 01/09/2011
378 01/10/2011 01/16/2011
379 01/17/2011 01/23/2011
380 01/24/2011 01/30/2011
381 01/31/2011 02/06/2011
382 02/07/2011 02/13/2011
383 02/14/2011 02/20/2011
384 02/21/2011 02/27/2011
441 02/28/2011 03/06/2011
442 03/07/2011 03/13/2011
443 03/14/2011 03/20/2011
444 03/21/2011 03/27/2011
451 03/28/2011 04/03/2011
452 04/04/2011 04/10/2011
453 04/11/2011 04/17/2011
454 04/18/2011 04/24/2011
455 04/25/2011 05/01/2011
456 05/02/2011 05/08/2011
457 05/09/2011 05/15/2011
458 05/16/2011 05/22/2011
459 05/23/2011 05/29/2011
460 05/30/2011 06/05/2011
461 06/06/2011 06/12/2011
462 06/13/2011 06/19/2011
463 06/20/2011 06/26/2011
464 06/27/2011 07/03/2011
465 07/04/2011 07/10/2011
466 07/11/2011 07/17/2011
467 07/18/2011 07/24/2011
468 07/25/2011 07/31/2011
469 08/01/2011 08/07/2011
470 08/08/2011 08/14/2011
471 08/15/2011 08/21/2011
472 08/22/2011 08/28/2011
473 08/29/2011 09/04/2011
474 09/05/2011 09/11/2011
475 09/12/2011 09/18/2011
476 09/19/2011 09/25/2011
477 09/26/2011 10/02/2011
478 10/03/2011 10/09/2011
479 10/10/2011 10/16/2011
480 10/17/2011 10/23/2011
481 10/24/2011 10/30/2011
482 10/31/2011 11/06/2011
483 11/07/2011 11/13/2011
484 11/14/2011 11/20/2011
485 11/21/2011 11/27/2011
486 11/28/2011 12/04/2011
487 12/05/2011 12/11/2011
488 12/12/2011 12/18/2011
489 12/19/2011 12/25/2011
491 12/26/2011 01/01/2012
492 01/02/2012 01/08/2012
493 01/09/2012 01/15/2012
494 01/16/2012 01/22/2012
495 01/23/2012 01/29/2012
496 01/30/2012 02/05/2012
497 02/06/2012 02/12/2012
498 02/13/2012 02/19/2012
499 02/20/2012 02/26/2012
500 02/27/2012 03/04/2012
501 03/05/2012 03/11/2012
502 03/12/2012 03/18/2012
503 03/19/2012 03/25/2012
504 03/26/2012 04/01/2012
505 04/02/2012 04/08/2012
506 04/09/2012 04/15/2012
507 04/16/2012 04/22/2012
508 04/23/2012 04/29/2012
509 04/30/2012 05/06/2012
510 05/07/2012 05/13/2012
511 05/14/2012 05/20/2012
512 05/21/2012 05/27/2012
513 05/28/2012 06/03/2012
514 06/04/2012 06/10/2012
515 06/11/2012 06/17/2012
516 06/18/2012 06/24/2012
517 06/25/2012 07/01/2012
518 07/02/2012 07/08/2012
519 07/09/2012 07/15/2012
520 07/16/2012 07/22/2012
521 07/23/2012 07/29/2012
522 07/30/2012 08/05/2012
523 08/06/2012 08/12/2012
524 08/13/2012 08/19/2012
525 08/20/2012 08/26/2012
526 08/27/2012 09/02/2012
527 09/03/2012 09/09/2012
528 09/10/2012 09/16/2012
529 09/17/2012 09/23/2012
530 09/24/2012 09/30/2012
531 10/01/2012 10/07/2012
532 10/08/2012 10/14/2012
533 10/15/2012 10/21/2012
534 10/22/2012 10/28/2012
535 10/29/2012 11/04/2012
536 11/05/2012 11/11/2012
537 11/12/2012 11/18/2012
538 11/19/2012 11/25/2012
539 11/26/2012 12/02/2012
540 12/03/2012 12/09/2012
541 12/10/2012 12/16/2012
542 12/17/2012 12/23/2012
543 12/24/2012 12/30/2012
544 12/31/2012 01/06/2013
545 01/07/2013 01/13/2013
546 01/14/2013 01/20/2013
547 01/21/2013 01/27/2013
548 01/28/2012 02/03/2012
I don't have week_enddate column I created it by adding 6 days to week_startdate.
the requirement is If i pass the date as input parameter between week_startdate and week_enddate I must get week_id
for example if i pass date between 04/02/2012 to 04/08/2012 I should get only that week_id
that is between
04/02/2012,
04/03/2012,
04/04/2012,
04/05/2012,
04/06/2012,
04/07/2012,
04/08/2012
I must get week_id 505 like that.The table dont have week_enddate I created in the select statement by adding 6 days but I should pass only startdate and I should get the week_id between two dates
help me
try the following query
select week_id
from dbo.TBL_S3_FISCALWEEKS_1
where #yourdate between week_startdate and convert(varchar,dateadd(day,6,week_startdate),101)