MySQL adding extra rows to a selection - numbers

Is it possible to format somehow the MySQL SELECT query, so if the records contain nonconsecutive numbers, the missing numbers to be added accordingly, i.e. if the database contains
765
767
768
769
772
773
778
779
780
the returned query to look like this:
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780

The trick was to get the consecutive numbers from a dummy table and LEFT JOIN the two tables.

Related

How to switch columns of a text file?

I want to switch columns order in a bunch of text files and also remove some of the columns after switching. I'm trying to use textscan function in matlab. But I'm not sure how to do it.
This is a sample line in one of the text files (space is delimiter):
580.697942 1009.223279 3.012318 2 1 0 554 605 607 558 1004 996 1016 1021
For example, I want to bring the forth-to-sixth column to the first of the line:
2 1 0 580.697942 1009.223279 3.012318 554 605 607 558 1004 996 1016 1021
And maybe add some columns (with value='0') afterwards.
I would appreciate some advice on how to do this.
Thanks
Instead of textscan, I would recommend you to use the dlmread function.
out = dlmread( 'mytextfile.txt' );
The output is an array, by using MATLAB basic commands you will be able to change columns as you wish.

Getting started with LibSVM for a particular case

I have read quite a lot about LibSVM library, but I would like to ask you for some advices in my particular case. The problem is that I have some 3D medical images (DCE-MRI) of a stomach. My goal is to perform a segmentation of a kidney, and find its three parts. Therefore, I need to train a classifier - I'm going to use SVM and neural network
Feature vectors:
What is available is the pixel (voxel) brightness value (I guess the value range is [0; 511]). In total, there are 71 frames, each taken every second. So the crucial feature of every voxel is how the voxel brightness/intensity is changing during the examination time. In my case, every part of a kidney has a different chart (see an example below), so the way how the voxels brightness is changing over the time will be used by the classifier.
Training sets:
Every training set is a vector of intensity value of one voxel (74 numbers). An example is presented below:
[22 29 21 7 19 12 23 25 33 28 25 5 21 18 27 21 11 11 26 12 12 31 15 15 12 29 17 34 30 11 12 24 35 28 27 26 29 22 15 23 24 14 14 37 241 313 350 349 382 402 333 344 332 366 339 383 383 379 394 398 402 357 346 379 365 376 366 365 360 363 376 383 389 385]
Summary and question to you:
I have many training sets consisting of 74 values from the range [0; 511]. I have 3 groups of voxels, which have a characteristic feature - the brightness is changing in the similar way. What I want to obtain is a classificator, which after getting one voxel vector with 74 numbers, will assess if the voxel belongs to one of these 3 groups, or to none of them.
Question: how to start with LibSVM, any advices? From what I know now is that I should transform input values to be from the range [0; 1] or [-1; 1]. I have many training sets prepared belonging to one of these 3 groups. I will be grateful for any advice, as I'm a newbie and I just need some tips just to start.
You can train and use you model like this:
model=svmtrain(train_label,train_feature,'-c 1 -g 0.07 -h 0');
% the parameters can be modified
[label, accuracy, probablity]=svmpredict(test_label,test_feaure,model);
train_label must be a vector,if there are more than two kinds of input(0/1),it will be an nSVM automatically. If you have 3 classes, you can label them using {1,2,3}.Its length is equal to the number of samples.
The feature is not restricted. It can be what ever you want.
However, you'd better preprocess them to make the results better. For example, you can change range[0:511] to range[0:1] or minus the mean of the feature.
Notice that the testset data should be preprocessed in the same way.
Hope this will help you!

Alternative to dec2hex in MATLAB?

I am using dec2hex up to 100 times in MATLAB. Because of this, the speed of code decreases. for one point I am using dec2hex 100 times. It will take 1 minute or more than it. I have do the same for 5000 points. But because of dec2hex it will take hours of time to run. So how can I do hexadecimal to decimal conversion optimally? Is there any other alternative that can be used instead of dec2hex?
As example:
%%Data[1..256]: can be any data from
for i=1:1:256
Table=dec2hex(Data);
%%Some permutation applied on Data
end;
Here I am using dec2hex more than 100 times for one point. And I have to use it for 5000 points.
Data =
Columns 1 through 16
105 232 98 250 234 216 98 199 172 226 250 215 188 11 52 174
Columns 17 through 32
111 181 71 254 133 171 94 91 194 136 249 168 177 202 109 187
Columns 33 through 48
232 249 191 60 230 67 183 122 164 163 91 24 145 124 200 142
This kind of data My code will use.
Function calls are (still) expensive in MATLAB. This is one of the reasons why vectorization and pseudo-vectorization is strongly recommended: processing an entire array of N values in one function call is way better than calling the processing function N times for each element, thus saving the N-1 supplemental calls overhead.
So, what you can do? Here are some non-mutually-exclusive choices:
Profile your code first. Just because something looks like the main culprit for execution time disasters, it isn't necessarily it. Type profview in your command window, chose the script that you want to run, and see where are the hotspots of your code. Choose to optimize those hotspots rather than your initial guesses.
Try faster functions. sprintf is usually fast and flexible:
Table = sprintf('%04X\n', Data);
(and — if you dive into the function code with edit dec2hex — you'll see that in some cases dec2hex actually calls sprintf).
Reduce the number of function calls. Suppose you have to build the table for the 100 datasets of different lengths, that are stored in a cell array:
DataSet = cell(1,100);
for k = 1:100
DataSet{k} = fix(1000*rand(k,1));
end;
The idea is to assemble all the numbers in a single array that you convert at once:
Table = dec2hex(vertcat(DataSet{:}));
Mind you, this is done at the expense of using supplemental memory for assembling the partial inputs in a single one — it's not always convenient to do that.
All the variants above. Okay, this point is not actually a point. :-)

Intelligently decide on the correct SI prefix for a number

I have a field in my MS Access database for the length of a DNA sequence.
DNA sequences are measured in basepairs (bp or b). This is an integer value. However, often they are between 1000-10000, so it is sometimes convenient to use kilobases (kb) instead.
In my field, I want to enter the value as integer showing the number of basepairs. I want Access to look at how big this number is, and if it is smaller than 100, display as #" bp", and otherwise divide it by 1000 and display as #.###" kb".
If possible, it would be great if I could also enter some numbers directly as kb, and have Access convert them to bp, provided this does not involve too many keystrokes per entry.
Is this possible in MS Access 2013? If so, how?
For display purposes, you could create a separate Text field and use it to store the formatted value. For a table named [dna]
id - AutoNumber, Primary Key
dnaSeqCount - Long Integer
dnaSeqDisplay - Text(100)
you could create a Before Change data macro like this
so you could enter the integer value into [dnaSeqCount] and have the [dnaSeqDisplay] formatted automatically:
id dnaSeqCount dnaSeqDisplay
-- ----------- -------------
1 1 1 bp
2 99 99 bp
3 100 0.100 kb
4 101 0.101 kb
5 109 0.109 kb
6 110 0.110 kb
7 111 0.111 kb
8 999 0.999 kb
9 1000 1.000 kb
10 1001 1.001 kb
11 1009 1.009 kb
12 1010 1.010 kb
13 1999 1.999 kb
14 2000 2.000 kb
15 2001 2.001 kb

Create a pivot table

I have the below excel data(and it is my backend)
Date Editor Units
7/1/2013 Amreen 158
7/2/2013 Amreen 23
7/3/2013 Amreen 1
7/6/2013 Amreen 33
7/3/2013 Amreen 77
7/3/2013 Amreen 66
7/3/2013 Anirudh 748
7/3/2013 Amreen 8
7/6/2013 Amreen 402
7/7/2013 Amreen 24
7/7/2013 Amreen 146
7/9/2013 Amreen 33
7/8/2013 Amreen 45
7/8/2013 Amreen 21
I want to create a pivot table using JasperReports. I'm new to this technology or framework(i'm not sure of what it is to be said as), can anybody help me to get the table in the below format with explanation. I'm really confused and unable to understand how to do it.
Amreen Anirudh Anand Total
7/1/2013 158 158
7/2/2013 23 23
7/3/2013 152 748 900
7/4/2013
7/5/2013
7/6/2013 435 435
7/7/2013 170 170
7/8/2013 66 66
7/9/2013 33 33 66
Total 1037 748 33 1818
if not the solution please give me a reference of this type of instances (Excel and JasperReports pivot).
Use the Cross table, with Edit in Column and Date in Row and Unit as sum in the middle.
You should be using Crosstab from the Palette. First create a datasource for you report which can be excel or any RDBMS. Then when you drag and drop the Crosstab from the palette a wizard will open. Just follow the wizard and your Pivot table will be done in no time. I hope this helps. For more info link