A matlab code to generate this figure - matlab

jan 0.23%
feb 2.56%
mar 0.76%
apr 4.19% <-- This is the highest value
may -0.36%
jun -1.68% <-- This is the lowest value
jul 1.18%
aug -0.99%
sep -1.43%
nov 2.32%
dec 1.88%
What code can generate exactly the figure above without apostrophe and without being too complicated. Using for loops maybe? Note that the color of all letters and numbers is black.
I tried the following code :
C={'jan' 0.23 ' ';'feb' 2.56 ' ';'mar' 0.72 ' ';'apr' 4.19 '<-- This is the highest value';'may' -0.36 ' ';'jun' -1.68 '<-- This is the lowest value';'jul' 1.18 ' ';'aug' -0.99 ' ';'sep' -1.43 ' ';'oct' 2.00 ' ';'nov' 2.32 ' ';'dec' 1.88 ' '}
And i got this
'jan' [ 0.2300] ' '
'feb' [ 2.5600] ' '
'mar' [ 0.7200] ' '
'apr' [ 4.1900] '<-- This is the highes…'
'may' [-0.3600] ' '
'jun' [-1.6800] '<-- This is the lowest…'
'jul' [ 1.1800] ' '
'aug' [-0.9900] ' '
'sep' [-1.4300] ' '
'oct' [ 2] ' '
'nov' [ 2.3200] ' '
'dec' [ 1.8800] ' '
But it's not even close to what i want, it is very incomplete, contains apostrophes and so.

Firstly, you have to find max and min value in second columns.
Then try using ``printf()'' to print out the columns, at the max and min index print the text.
Sorry, i'm using mobile so I can't write the answer in detail.

Related

Correct statement for UNION ALL with three or more selects

I have the following situation:
I have a script consisting of 6 selects joined by "UNION ALL".
From the CLP DB2 console, this script fails. Curiously, each query independently work, and even come to work if grouped in pairs. However, when I try with three or more, it fails.
So, my question is: is there is a limit for more that one UNION ALL?
My environment is:
Client. DB2 Connect server 10.1
zOS 390 (no idea what is the DB2 version on that side)
AIX 7.1
The query is like this (but three times )
SELECT
,'GG'
,varchar(right( '000000000000000' || rtrim(ltrim(eeee.zzzz)), 15), 15)
,substr(char(right('**********'||char(left(replace(eeee.yyyy,' ','*')||'**********',10),10),10),10),1,7)
,eeee.kkkkk
,eeee.hhhhhh
,CASE WHEN hhhhhh='A5 ' THEN 'ARS' WHEN hhhhhh='A6 ' THEN 'AUD' WHEN hhhhhh='B5 ' THEN 'BRL' WHEN hhhhhh='U1 ' THEN 'GBP' WHEN hhhhhh='B9 ' THEN 'BND' WHEN hhhhhh='B6 ' THEN 'BNG' WHEN hhhhhh='C1 ' THEN 'CAD' WHEN hhhhhh='C3 ' THEN 'CLP' WHEN hhhhhh='C4 ' THEN 'CNY' WHEN hhhhhh='C5 ' THEN 'COP' WHEN hhhhhh='C7 ' THEN 'CRC' WHEN hhhhhh='L5 ' THEN 'HRK' WHEN hhhhhh='C9 ' THEN 'CYP' WHEN hhhhhh='X0 ' THEN 'CZK' WHEN hhhhhh='D0 ' THEN 'DKK' WHEN hhhhhh='D1 ' THEN 'DOP' WHEN hhhhhh='U0 ' THEN 'EGP' WHEN hhhhhh='E3 ' THEN 'EUR' WHEN hhhhhh='G5 ' THEN 'GTQ' WHEN hhhhhh='H0 ' THEN 'HTG' WHEN hhhhhh='H3 ' THEN 'HUF' WHEN hhhhhh='I1 ' THEN 'INR' WHEN hhhhhh='I2 ' THEN 'IDR' WHEN hhhhhh='K2 ' THEN 'WON' WHEN hhhhhh='L6 ' THEN 'LVL' WHEN hhhhhh='L7 ' THEN 'LTL' WHEN hhhhhh='M2 ' THEN 'MYR' WHEN hhhhhh='M6 ' THEN 'MXN' WHEN hhhhhh='I8 ' THEN 'ILS' WHEN hhhhhh='N2 ' THEN 'NZD' WHEN hhhhhh='N4 ' THEN 'NIO' WHEN hhhhhh='N6 ' THEN 'NOK' WHEN hhhhhh='T4 ' THEN 'XPF' WHEN hhhhhh='P0 ' THEN 'PKR' WHEN hhhhhh='P1 ' THEN 'PAB' WHEN hhhhhh='P3 ' THEN 'PEN' WHEN hhhhhh='P4 ' THEN 'PHP' WHEN hhhhhh='P5 ' THEN 'PLN' WHEN hhhhhh='R2 ' THEN 'RON' WHEN hhhhhh='U3 ' THEN 'RUB' WHEN hhhhhh='S0 ' THEN 'SAR' WHEN hhhhhh='R6 ' THEN 'RSD' WHEN hhhhhh='S2 ' THEN 'SGD' WHEN hhhhhh='K5 ' THEN 'SKK' WHEN hhhhhh='S4 ' THEN 'ZAR' WHEN hhhhhh='C2 ' THEN 'LKR' WHEN hhhhhh='S8 ' THEN 'SEK' WHEN hhhhhh='S9 ' THEN 'CHF' WHEN hhhhhh='T2 ' THEN 'THB' WHEN hhhhhh='T6 ' THEN 'TRL' WHEN hhhhhh='U4 ' THEN 'USD' WHEN hhhhhh='U6 ' THEN 'UAH' WHEN hhhhhh='U5 ' THEN 'AED' WHEN hhhhhh='U2 ' THEN 'UYU' WHEN hhhhhh='V0 ' THEN 'VEB' WHEN hhhhhh='V1 ' THEN 'VND' WHEN hhhhhh='J1 ' THEN 'JPY' ELSE '###' END
, case when eeee.FCRCIDF='Y' then 1 else 0 end
,
CASE
WHEN SUBSTR(eeee.yyyy,7,1) = 'X' THEN 'X'
WHEN SUBSTR(eeee.yyyy,4,2) = 'O' THEN 'O'
WHEN SUBSTR(eeee.yyyy,4,2) = 'C' THEN 'C'
WHEN SUBSTR(eeee.yyyy,4,2) = 'R' THEN 'R'
WHEN eeee.lll = 'F' THEN 'F'
WHEN eeee.ppp <> '' THEN 'D'
WHEN eeee.rrr = 0 THEN '0'
WHEN eeee.rrr <> eeee.ACINTOT THEN 'P'
WHEN eeee.rrr = eeee.ACINTOT THEN '1'
ELSE '*'
END
,1
,eeee.DCINISS
,0
from (SELECT ori.*,oric.tttt FROM www.SK1V01_CUSTOMER ori left OUTER JOIN www.SK1V01A_CUSTCUF oric
ON ori.bbbb=oric.bbbb and ori.ICUSCNO=oric.ICUSCNO ) as aaaa
,www.SK1V02_OPENBILL eeee,www.SK1V41_OPENBILL kkkk
where aaaa.bbbb=eeee.bbbb
and aaaa.cagllic=eeee.cagllic
and aaaa.icuscno=eeee.icuscno
Without the entire statement its pretty hard to determine exact reasons. An given that just one portion is so long & poorly formatted, I'm not sure we'd want to dig through it all. But I can suggest a few approaches that may help resolve your problem.
Simplest part first. In practically any computer language, well formatted code helps you see the structure of what's going on. It may also help you spot the differences between your queries. (Perhaps you know this, & your code merely lost its formatting when you tried to post it.)
When trying to UNION multiple complex queries, it's not uncommon to have column inconsistencies among the queries. You might have missing or extra columns, or columns out of order. But it's possible some of your column expressions are evaluating to different types. You might want to cast() those expressions, or use type conversion functions, just to be sure.
There's so much going on here. Try testing with a version where you comment out large chunks of code, same on each major subquery, until you find which part is causing the problem.
You have a ridiculously long CASE expression on hhhhhh. Why don't you put these value pairs into a lookup table that you can join to.
Try using a module approach, just as you should when writing a large program. You could create a view for each of the major queries, then UNION them together. (Some developers use layers of views like layers of modular code).
Metadata about your views is available in the database catalog views. This means you could write a query to compare the attributes of the columns in your set of union views.

nvarchar to time conversion

I have to develop system which is accept data (in database) from another system. The problem I face is all DATE and TIME data is in NVARCHAR. I have to convert to DATE and TIME in order to calculate the duration. I am using SQL Server 2008 R2.
Data example:
STR_YMD STR_HMS
--------------------
20150101 151000
20090807 123009
20130113 145602
20090515 061700
How could I convert this data into following DATETIME data?
STR_DT
--------------------
2015-01-01 15:10:00
2009-08-07 12:30:09
2013-01-13 14:56:02
2009-05-15 06:17:00
Hopefully someone could help me. Thanks in advance
Bet
Something like this ?
SELECT CAST(SUBSTRING(STR_YMD, 1, 4) + '/' + SUBSTRING(STR_YMD, 5, 2) + '/' +
SUBSTRING(STR_YMD, 7, 2) + ' ' + SUBSTRING(STR_HMS, 1, 2) + ':' +
SUBSTRING(STR_HMS, 3, 2) + ':' + SUBSTRING(STR_HMS, 5, 2) AS DateTime)
EDIT : You can use LEFT function to be compatible with short time formats :
SELECT CAST(SUBSTRING(STR_YMD, 1, 4) + '/' + SUBSTRING(STR_YMD, 5, 2) + '/' +
SUBSTRING(STR_YMD, 7, 2) + ' ' + SUBSTRING(LEFT(STR_HMS+'000000', 6), 1, 2) + ':' +
SUBSTRING(LEFT(STR_HMS+'000000', 6), 3, 2) + ':' +
SUBSTRING(LEFT(STR_HMS+'000000', 6), 5, 2) AS DateTime)

Remove any spaces between ' ' in cell array Matlab

I have this cell array
aitransp =
Columns 1 through 14
'27' '26' '25' '24' '23' '22' '21' '20' '19' '18' '17' '16' '15' '14'
Columns 15 through 21
'13' '12' '11' ' 9' ' 8' ' 7' ' 1'
As you can see, the last 4 elements have a space between the ' ', such as ' 9'.
Is there any way to remove any spaces occurring between '' in a cell array?
Thanks in advance..
Just use strtrim, you don't have to convert to string
strtrim(aitransp)
You can use regular expressions for greater flexibility:
result = regexprep(aitrasp, '(^\s*)' , ''); %// remove only leading space
result = regexprep(aitrasp, '(^\s*)|(\s*$)' , ''); %// remove leading or trailing space
result = regexprep(aitrasp, '\s' , ''); %// remove any space
for ii = 1:numel(aitransp)
aitransp{ii}(aitransp{ii} == ' ') = '';
end
This should do the trick.

white space in cell array

I am using textscan to read text file and I get <55x1 cell>
examples:
'aa a aa'
'a aaaa a'
'a = aaaaa'
'aaaaaa'
' a a a aaa'
'aa'
'aaa'
'aaaa'
.
.
.
.
I want to delete the white spaces in each sting
If I have a sting
string = 'I am 24 Years old'
And I use
string(ismember(string,' ')) = [];
it will eliminate the spaces and I will get
'Iam24Yearsold'
But with the cell doesn't work or I don't know how to do it
How can I do that? any suggestions please?
You can use strrep:
a = { 'aa a aa'
'a aaaa a'
'a = aaaaa'
'aaaaaa'
' a a a aaa'
'aa'
'aaa'
'aaaa'
'I am 24 Years old'};
strrep(a, ' ', '')
This results in
ans =
'aaaaa'
'aaaaaa'
'a=aaaaa'
'aaaaaa'
'aaaaaa'
'aa'
'aaa'
'aaaa'
'Iam24Yearsold'

Web::Query and data extraction

I had a problem with scraping info from a web page, which was solved by someone, but i would also like to get the data from that structure and put it into normal string variables, i commented saying this and was told to create a new question, so here it is!
code:
use Web::Query 'wq';
my $football_matches = wq($mech->content)
->find('tr.match')
->map(sub {
my (undef, $e) = #_;
return 'v' eq $e->find('td.score')->text
? [
$e->attr('id'),
map { $e->find("td.$_")->text }
(qw(tournament dateTime homeTeam score awayTeam prices))
]
: ();
});
use Data::Dumper; print Dumper $football_matches;
output:
$VAR1 = [
['tn7gc635476', '', ' Mo 12Mar 2012 ', 'Arsenal', 'v', 'Newcastle', ' '],
['tn7gc649937', '', ' Tu 13Mar 2012 ', 'Liverpool', 'v', 'Everton', ' '],
['tn7gc635681', '', ' Sa 17Mar 2012 ', 'Fulham', 'v', 'Swansea', ' '],
['tn7gc635661', '', ' Sa 17Mar 2012 ', 'Wigan', 'v', 'West Brom', ' '],
['tn7gc635749', '', ' Su 18Mar 2012 ', 'Wolves', 'v', 'Man Utd', ' '],
['tn7gc635556', '', ' Su 18Mar 2012 ', 'Newcastle', 'v', 'Norwich', ' ']
];
What i would like to do is take each date, home team and away team and put them into normal variables/arrays.
Thanks in advance!
You may want to check perldsc and perlref. Look for the part arrays-of-arrays and arrayref