w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
functions operating columnwise on gpuArrays in matlab
If you had multi GPU you could use spmd or parfor. You want a low level access to your GPU resources which you can have only using CUDA and Mex files. The book Accelerating MATLAB with GPU Computing might be the right point to start.

Categories : Matlab

Easiest way to count cross platform newline patterns
What you're doing is pretty good. Another way to do it is to split the buffer on nlinePat and process each line, knowing that you can add 1 to nlineCount each time you process a line. My solution means you won't be keeping track of the number of characters (because the split may split on one or two charcters, and you don't know how many whitespace characters are stripped). I think you will have a hard time finding a way to do this "in python", you need to do more than one thing at a time (count newlines and count characters) so maybe you should parse it character by character yourself. My example: #!/usr/bin/env python import re buffer = ''' Now is the time for all good men to come to the aid of their party. ''' nlinePat = re.compile(r' ?| ') bufferPos = 0 nlineCounter = 0

Categories : Python

Append data columnwise in C/C++
Consider the file to be one long stream of characters, some of them just happen to be line breaks. Append always starts at the end of the file. If I'm reading you right you need to use seekp(seek new position to put new characters at) on your fstream to get to the right position before writing. You know the format of your file, therefore you can calculate how much to skip in each line. Something like this might work: read line while line != "": skip forward the right number of " " write new column read new line

Categories : C++

Printing Columnwise in Excel using ORA_EXCEL package
Try this: declare doc_id pls_INTEGER:=0; sheet_id pls_INTEGER:=0; row_id pls_INTEGER:=0; begin doc_id := ora_excel.new_document; sheet_id := ora_excel.add_sheet('Sheet 1',doc_id); row_id := ora_excel.add_row; ora_excel.set_cell_value('A','Row1', doc_id,sheet_id, row_id); ora_excel.set_cell_value('B','Row1B', doc_id,sheet_id, row_id); row_id := ora_excel.add_row; ora_excel.set_cell_value('A','Row2',doc_id,sheet_id, row_id); ora_excel.set_cell_value('B','Row2B', doc_id,sheet_id, row_id); row_id := ora_excel.add_row; ora_excel.set_cell_value('A','Row3', doc_id,sheet_id, row_id); ora_excel.set_cell_value('B','Row3B', doc_id,sheet_id, row_id); ora_excel.save_to_file('FTP_FOLDER','excel.xlsx',doc_id); end; Check this link: http://www.oraexc

Categories : Oracle

RowWise & ColumnWise Total of Output Table in MYSQL
Try SELECT c1, c2, c3, c4, c5, c1+c2+c3+c4+c5 c6 FROM table1 UNION ALL SELECT SUM(c1), SUM(c2), SUM(c3), SUM(c4), SUM(c5), SUM(c1+c2+c3+c4+c5) FROM table1 Output: | C1 | C2 | C3 | C4 | C5 | C6 | --------------------------------------- | 45 | 416 | 0 | 0 | 0 | 461 | | 7887 | 0 | 0 | 0 | 0 | 7887 | | 444 | 0 | 1628 | 0 | 0 | 2072 | | 8376 | 416 | 1628 | 0 | 0 | 10420 | Here is SQLFiddle demo

Categories : Mysql

how to get the length (count of rows) of this matlab matrix?
Just use the size function size(ans, 1) But if you're asking this, I suggest you work through some basic Matlab tutorials before you continue...

Categories : Matlab

Matlab count the number of occurrences of a two columns
Here is the code for the first result: A = [4565,345;325,6843;4565,4565;321,9876;6843,321;6843,321;6843,6843;9876,9876;6843,9876] A_cols = {num2cell(A(:,1)'),num2cell(A(:,2)')}; A_rows = cellfun(@(varargin)[varargin],A_cols{:},'un',0); A_flippedlo_rows = cellfun(@(x) feval(@(varargin) varargin{3-varargin{1}}(), x{1}<x{2}, fliplr(x), x), A_rows, 'un', 0); boolvec = cell2mat(cellfun(@(x) bitand(x{1}>1000, x{2}<1000),A_flippedlo_rows,'un',0)); A_hilo_rows = A_flippedlo_rows(boolvec); A_hilo_cols = cellfun(@(varargin)[varargin],A_hilo_rows{:},'un',0); A_hilo = [cell2mat(A_hilo_cols{1});cell2mat(A_hilo_cols{2})]' [A_hilo_unique, iA_hilo, iA_hilo_unique] = unique(A_hilo, 'rows'); firstresult = [A_hilo_unique accumarray(iA_hilo_unique, ones(1,length(A_hilo)))] A = 4565 345

Categories : Matlab

Count frequencies of pairs in matrix matlab
This is one way of doing it: [~, ~, n1] = unique(X(:,1)); [~, ~, n2] = unique(X(:,2)); B = accumarray([n2 n1],1); S = B*B'; This gives the full matrix: >> S S = 3 2 0 0 2 5 0 0 0 0 1 1 0 0 1 1 To remove the diagonal and lower triangle you can use S = triu(B*B',1); which yields >> S S = 0 2 0 0 0 0 0 0 0 0 0 1 0 0 0 0

Categories : Matlab

cumulative frequency count of identical elements in a vector - matlab
You could create a function like the following: C = [1 1 2 2 2 3 3 4] Y = zeros(1,length(C)) helper = zeros(1,max(C)) % stores the count for each value for i=1:length(C) helper(C(i)) = helper(C(i))+1; %increases the count for the value in C(i) Y(i) = helper(C(i)); end Hope that helps

Categories : Matlab

How to count overlapped objects and objects with more than 1 colors in Matlab
First, you need to clearly define your input data- what types of objects do you want to detect (books, people, any types of objects?), what is the range of environmental conditions (smooth background vs. textured, lighting, perspective). Then try out various image segmentation techniques and seeing what works for your range of input data. There is no "right" answer - it all depends on your data. You might also try to incorporate prior information- things that you know when evaluating a scene, that a computer will not know by just evaluating pixels. For example, maybe all objects are of some minimum size. So your algorithm can filter to only return objects having pixelArea > minArea. Maybe you only expect one objet of each color. So if the color histogram of two detected objects ma

Categories : Matlab

Disqus count.js returns the wrong comment count and reaction count
Specify the absolute URL associated with that thread in your comment count href link instead of the relative url which you are currently using. The absolute URL should would be: <a href="http://in-the-attic.com/2013/01/04/building-a-blog-using-jekyll-bootstrap-and-github-pages-a-beginners-guide/">Comments</a> If you are still not seeing the correct count display for that particular thread, you can use an identifier: <a href="http://in-the-attic.com/2013/01/04/building-a-blog-using-jekyll-bootstrap-and-github-pages-a-beginners-guide/" data-disqus-identifier="EXAMPLE">Comments</a> Keep in mind that you cannot use the identifier until you have set one for that thread within the Javascript configuration variables

Categories : Misc

What is the difference between count(0), count(1).. and count(*) in mySQL/SQL?
Nothing really, unless you specify a field in a table or an expression within parantheses instead of constant values or * Let me give you a detailed answer. Count will give you non-null record number of given field. Say you have a table named A select 1 from A select 0 from A select * from A will all return same number of records, that is the number of rows in table A. Still the output is different. If there are 3 records in table. With X and Y as field names select 1 from A will give you 1 1 1 select 0 from A will give you 0 0 0 select * from A will give you ( assume two columns X and Y is in the table ) X Y -- -- value1 value1 value2 (null) value3 (null) So, all three queries return the same number. Unless you use select count(Y) from A since there is only one non

Categories : Mysql

Launching Matlab from java ProcessBuilder, Matlab console doesn't appear in Mac OS 10.8
You need to specify that MATLAB is to run with a visible UI by making use of the -desktop flag. I don't believe this is documented. So the command you need to run is matlab -desktop -r "initMatlab;runJavaUI;" I've created a Java library called matlabcontrol that can abstract all of this away from you. It can launch MATLAB while running on Windows, OS X, and Linux and then allow you to interact with MATLAB via eval and feval commands. matlabcontrol's code to launch MATLAB is located in matlabcontrol.RemoteMatlabProxyFactory's createProcess(...) method. If you make use of matlabcontrol as a Java library you won't directly interact with either this class or this method.

Categories : Java

How to apply a trained Matlab neural network from C++ without call to Matlab?
Of course it is possible - neural networks are clear mathematical models. All you need is a compatible representation, where you have stored: network topology (number of neurons in particuluar layers) network weights (between all neurons) network activation functions (for each neuron) And that's all. The exact solution depends on what matlab library you are using for neural networks. There is a "standard" for prediction models called PMML, which can be loaded by for example Weka libraries. Either way - it is easy operation, so you can also implement it by hand by simply storing all the numbers in the text file and simulating network in the C++ (as the "forward" phase of the neural network is just few lines of code - the training part is the long one).

Categories : C++

Will Matlab standalone be faster than Matlab from UI for long execution code?
Applications built with MATLAB Compiler should execute at pretty much exactly the same speed as within MATLAB. MATLAB Compiler does not convert your MATLAB code into machine code in the same way as a C compiler does for C. What it does is to archive and encrypt your MATLAB code (note, it properly encrypts it, not just pcodes it as a comment suggests), create a thin executable wrapper and package them together, possibly also with MATLAB Compiler Runtime (MCR). MCR is very similar to MATLAB itself, without a graphical user interface, and is freely redistibutable. When you run the executable, it dearchives and decrypts your MATLAB code and runs it against the MCR. It should run exactly the same, both in terms of results and speed. Very old versions of MATLAB Compiler (pre-version 4.0) work

Categories : Matlab

Matlab: Improper index matrix reference (or outsmarting matlab)
In the latest versions of MATLAB (13a/13b) there's a unit testing framework built in that looks very similar to what you're attempting. Instead of expect(myfibonacci(0)).toBe(0); you would write import matlab.unittest.constraints.IsEqualTo testCase.verifyThat(myfibonacci(0), IsEqualTo(0)) (You could also/instead have assumeThat, assertThat, or fatalAssertThat). If for some reason you wish to implement your own framework, note the small difference in your syntaxes - you have a dot whereas MathWorks have a comma between myfibonacci(0) and the test condition. In MATLAB you can't index into the result of a subscripted expression like that (well, you could, but you would have to overload subsref, and that's a world of pain, trust me). So the way they've done it is to introduce the test

Categories : Matlab

ORM and DAO design patterns
You have to create a "dao" abstraction layer to do this. Your service layer, which contains the business logic, should call the dao layer to fetch any DTOs. The dao layer should contain contracts/interfaces and implementation (based on Hibernate, JDBC or others). You should be able to configure your dao implementation selection via some externalized configuration (to prevent a re-compile after any change in dao layer implementation selection). View Layer > Service Layer > Dao Layer (HibernateImpl or JdbcImpl or etc.) > fetch data from db into DTOs and return it to caller.

Categories : Java

what is the difference between the patterns X? and X?
Both can match a single optional X. The difference is that X? is greedy which means it always tries to match the X first, and only gives up the match if that's necessary for the overall regex to match. X?? by contrast is lazy, always trying to match the empty string first and only matching X if necessary for the overall match. For example, compare the outputs of Pattern greedy = Pattern.compile("X?"); Matcher greedyMatcher = greedy.matcher("X"); if (greedyMatcher.find()) { System.out.println(greedyMatcher.group()); } versus Pattern lazy = Pattern.compile("X??"); Matcher lazyMatcher = lazy.matcher("X"); if (lazyMatcher.find()) { System.out.println(lazyMatcher.group()); }

Categories : Java

3 Regexp Patterns into one
You shouldn't really be using regular expression to parse HTML. You could use some parser, such as the PHP Simple DOM Parser to do that, for the same reason @Marty Wallace suggested. Also, your regular expressions are already relatively complex as they are, trying to merge them will only make it a maintenance nightmare.

Categories : PHP

Validating different patterns
For phone number, try this: (?d{3})?[ .-]?d{3}[ .-]?d{4} [ .-]? is basically saying "one or zero" of space, hyphen, or dot. For ssn: d{3}[ -]?d{2}[ -]?d{4} [ -]? is basically saying "one or zero" of space or hyphen. But honestly rather than care about format (which might frustrate user and you - trying to account for various formats), in most cases I'd rather just make sure they have the right amount of numbers. You could remove any non-numeric character and then check the length. How this is done would depend on the language being used. In javascript, it could look as simple as: if(phoneNumber.replace(/D/g, "").length() === 10){ //valid } Then you could format or use it however you want from that point. Here is a javascript example of that: fiddle... an example using a speci

Categories : Regex

MatLab-->csv: Export data to csv file using dlmwrite in Matlab
I think the problem is that you write the names to a file at the local folder and not the other folder. fldr = fullfile('c:','Data_Analysis'); nomFile=fullfile( fldr, 'Test.csv' ); fid=fopen(nomFile,'w'); fprintf(fid,'%s,',names{:}); fprintf(fid,' '); dlmwrite(nomFile,A,'-append'); fclose(fid);

Categories : Matlab

MATLAB - What are the units of Matlab Camera Calibration Toolbox
I know next to nothing about matlabs (not entirely true but i avoid matlab wherever I can, and that would be almost always possible) tracking utilities but here's some general info. Pixel dimension on the sensor has nothing to do with the size of the pixel on screen, or in model space. For all purposes a camera produces a picture that has no meaningful units. A tracking process is unaware of the scale of the scene. (the perspective projection takes care of that). You can re insert a scale by taking 2 tracked points and measuring the distance between those points. This is the solver spaces distance is pretty much arbitrary. Now if you know the real distance between these points you can get a conversion factor. By doing: real distance / solver space distance. There's really now way to kno

Categories : Matlab

MATLAB: checkmark in MATLAB figure with LaTeX interpreter
it's not pretty, but might be good enough: xlabel('$surd$','interpreter','latex') or look here for other things that look like a tick http://detexify.kirelabs.org

Categories : Matlab

Run Matlab executable file with MATLAB Compiler Runtime (MCR)
It simply means that you don't have rights to run PROGRAM. What is the output of the command: ls -l PROGRAM ? Maybe you've compiled this program as a root? Try to change the access using chmod.

Categories : Matlab

Django: conditional URL patterns?
Try this: if settings.IS_PRODUCTION: additional_settings = patterns('', (r'^robots.txt$', direct_to_template, {'template': 'robots_production.txt', 'mimetype': 'text/plain'}), ) else: additional_settings = patterns('', (r'^robots.txt$', direct_to_template, {'template': 'robots_dev.txt', 'mimetype': 'text/plain'}), ) urlpatterns += additional_settings Since you are looking to append tuple types , append does not work. Also, pattern() calls the urlresolver for you. In your case you were not, hence the error.

Categories : Django

Grunt Globbing patterns
You should be able to get the matching you need by passing two elements in the files array: files: [ '.tmp/*.html', '.tmp/views/**/*.html', ] This will match any .html files directly below .tmp/, as well as any .html file in .tmp/views/, whether directly under that directory or deeper (the /**/ part).

Categories : Javascript

Awk between two patterns with pattern in the middle
This awk should work: awk '$1=="Start"{ok++} ok>0{a[b++]=$0} $1=="middle"{ok++} $1=="End"{if(ok>1) for(i=0; i<length(a); i++) print a[i]; ok=0;b=0;delete a}' file Start 1 2 middle 3 End Expanded: awk '$1 == "Start" { ok++ } ok > 0 { a[b++] = $0 } $1 == "middle" { ok++ } $1 == "End" { if (ok > 1) for (i=0; i<length(a); i++) print a[i]; ok=0; b=0; delete a }' file

Categories : Linux

301 Redirect/Rewrites with Patterns
Use a RedirectMatch instead: RedirectMatch 301 ^/collection/([^/-]+)-active/(.*)$ /collection/active/$2 Assuming by the "is the changed part", you mean there could be anything where it says "womens-". EDIT: Since it's the other way around, just swap the regex grouping and the "womens-": RedirectMatch 301 ^/collection/womens-([^/-]+)/(.*)$ /collection/$1/$2

Categories : Regex

SQL Server - Group bit patterns of 101 and 11
Try this: select Id, [Bit] , case gr when 0 then Id - row_number() over(partition by gr order by Id) else row_number() over(partition by gr order by Id) end as [Group] from ( select Id, b0 as [Bit] , case when (b0 = 1 and b1 = 1) or (b0 = 1 and b1 = 0 and b2 = 1) or (b_1 = 1 and b0 = 0 and b1 = 1) then 0 else 1 end as gr from ( select Id+x as Id , min(case x when -1 then b end) b_1 , min(case x when 0 then b end) b0 , min(case x when 1 then b end) b1 , min(case x when 2 then b end) b2 from ( select Id, cast([Bit] as int) as b from MyTable ) T cross join (values(-1),(0),(1),(2))x(x) group by Id+x h

Categories : SQL

sed replace in conf 2 different patterns
It is happening because your first matching regex is: server: 127.0.0.1 And 2nd one is: next_server: 127.0.0.1 As you can see first regex will match both the patterns since server: 127.0.0.1 is found for both cases. Fix: To avoid unwanted matching you need to use word boundaries like this: sed -i.bak 's/(server: )127.0.0.1/1xxx.xxx.xxx.xxx/' /etc/cobbler/settings Note: On OSX you need to use this weird syntax for word boundaries: sed -i.bak 's/[[:<:]](server: )127.0.0.1/1xxx.xxx.xxx.xxx/' /etc/cobbler/settings

Categories : Bash

Vim: sort using multiple patterns
Assuming that you have external sort available, the following should work: :%!sort -k1,1 -k3,3n EDIT: Explanation: -k is used to specify sort keys. -k1,1 implies start sort on key1 and end it key1. -k3,3n implies start sort on key3 and end it key3; n here denotes numeric sort, i.e. compare according to string numerical value. By default, sort assumes blank to non-blank transition as the field separator. As such, it'd consider the line bar b 1 to comprise of three fields. If the values were delimited by a specific character other than space, say :, you would specify the field-separator by adding -t:.

Categories : Regex

Discover long patterns
Just to start with something, here is a simple solution in JavaScript: var input = [0.7, 1, 2, 3, 4, 7, 15, 27, 30, 31, 81], output = [], indexes, values, i, index, value, i_max_length, i1, i2, i3, j1, j2, j3, difference12a, difference23a, difference12b, difference23b, scale_factor, common_ratio_a, common_ratio_b, common_ratio_c, error, EPSILON = 1e-9, common_ratio_is_integer, resultDiv = $("#result"); for (i1 = 0; i1 < input.length - 2; ++i1) { for (i2 = i1 + 1; i2 < input.length - 1; ++i2) { scale_factor = difference12a = input[i2] - input[i1]; for (i3 = i2 + 1; i3 < input.length; ++i3) { difference23a = input[i3] - input[i2]; common_ratio_1a = difference23a / difference12a; common_ratio_2a = Math.rou

Categories : Algorithm

JAX-RS Webservice Architecture Patterns
I don't see anything wrong with transactions being managed by the service layer. That's where the context to decide what should be atomic is and should be. Your service layer doesn't need to be EJBs unless you plan to distribute them. You can use JDO or JPA transactions to manage persistence operations. Your "Persistence Layer" doesn't really need to be EJBs either unless you plan to distribute them.

Categories : Java

TypeScript Javascript patterns
MyTemplate solution Provide two interfaces to the user. One that he can use to add new templates to Template. Another to allow him to specify the features of a Template: interface ITemplate{ } interface ITemplateStatic{ events:Function; } declare var Template:ITemplate; // the user's code: interface ITemplate{ myTemplate:ITemplateStatic; } Template.myTemplate.events({}); This solution To answer your second question about this. The only way to do that is to expose the signatures as an interface. It is then the responsibility of the typescript user to get the proper type if he needs it. There is no way to implicity specify the type of this inside a function. declare module meteor{ interface IMethod{ // A simple sample isSimulation:boolean; } }

Categories : Meteor

RegEx to match the patterns
Maybe something like this... /^[./:a-z]([0-9]+/)?[a-z]+[^?]*$/ Explained here... /^ # Start regex, and start matching [./:a-z] # starts with dot, slash, colon or a-z ([0-9]+/)? # optionally has multi-digit number followed by slash [a-z]+ # has one or more letters next [^?]* # has zero or more characters that are not `?` $/ # end of matching and end regex Hard to know the specifics of what you are aiming for Tests in... Coffeescript rex = /^[./:a-z]([0-9]+/)?[a-z]+[^?]*$/ for str in """ .domain .domain.com .domain.com/path .domain.com:443/path domain.com domain.com/path domain.com:443/path domain /path :443/path """.split /[ ]+/ console.log "Should be true - is #{if str.match rex then 'true ' else 'fals

Categories : Javascript

OO Design Patterns with Perl
You gotta ask yourself one question. Does it matter to a cat which organization a cat or a box belongs to? E.g., when you have a cat object, do you even need to know its owner? Is there a functionality that starts with a cat, and does something owner specific - WITHOUT knowing the owner before you even know the cat object? E.g. a typical functionality would always start with a user: my $org = $user->org(); Proceed to find its cats my @cats = $org->listOwnedCats(); And then do something with one of the cats: $cats[0]->CheckHealth(); Note the important fact: by the time you get to the specific cat - you already KNOW the organization since that was how you got the cat object in the first place. There's zero need to store $org inside the $cat object. Same is true for the c

Categories : Perl

Incomplete match with AND patterns
If you code the destinction between ground terms and complex terms into the type system, you can avoid the runtime check and make them be complete pattern matches. type Num = int type Name = string type GroundTerm = | Con of Num | Var of Name type ComplexTerm = | Add of Term * Term | Sub of Term * Term | Mult of Term * Term | Div of Term * Term | Pow of Term * Term | Neg of Term and Term = | GroundTerm of GroundTerm | ComplexTerm of ComplexTerm let (|Operator|) ct = match ct with | Add(_) -> "+" | Sub(_) | Neg(_) -> "-" | Mult(_) -> "*" | Div(_) -> "/" | Pow(_) -> "**" let (|Unary|Binary|) ct = match ct with | Add(x, y) -> Binary(x, y) | Sub(x, y) -> Binary(x, y) | Mult(x, y) -> B

Categories : F#

what is the right way to do conditional patterns in dust.js
I think e answer depends on the complexity of the different components. If the logged in menu and the login form are both relatively simple, they could easily be included in a single partial. If they are complex (or you suspect they may become more complex in the future), then breaking them out into separate "partials" may be the best approach. Extra templates come with a small overhead cost, but it is pretty minimal. Additionally, if you start out with a single template and things start to get complex, it is pretty easy to break things out into separate partials.

Categories : Node Js

Understanding URL patterns in django
A request to /75/ or /3/ would call the function views.confirm(itemnum='75') or views.confirm(itemnum='3'). The variable itemnum can hold any number. You can read more about url dispatcher here.

Categories : Python

Join lines between patterns
quick and dirty: (gawk needed): awk -v RS="" '{gsub(/ sizes*=s*0s*}/," size = 0}")}1' file test with a file with your question text as content: kent$ cat test.txt I have files with paterns delimited by {}, on my source files sometimes I have two lines like this: { some text size = 0 } or { some text size = 0 } and other cases {some text size = 0 } {this should stay as it is } kent$ awk -v RS="" '{gsub(/ sizes*=s*0s*}/," size = 0}")}1' test.txt I have files with paterns delimited by {}, on my source files sometimes I have two lines like this: { some text size = 0} or { some text size = 0} and other cases {some text size = 0} {this should stay as it is }

Categories : Bash



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.