Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 151754

Performance is a subset of Optimization: performance is the goal when you want the execution time of your program or routine to be optimal.

2 votes

Performance Optimization in Matlab

Although the code in the question is not complete, there are sufficient bad practices in the snippet that I wanted to post an answer. Repeated computation in a loop When you do a computation or an ind …
Cris Luengo's user avatar
  • 6,237
4 votes
Accepted

Generating locations based on a power-law distribution of distance from their origin

Looking at your code again, there are a few things that you could try: 1. Avoid trigonometric functions These seem to be the most expensive part of your code. You compute a single uniformly distribu …
Cris Luengo's user avatar
  • 6,237
2 votes
Accepted

considering only the instants of trading with the relative price avoiding stale returns

To speed up code you have to start with two things: Pay attention to the warnings that the MATLAB Editor gives you: Four lines have red squiggles underneath, hovering over them says "Variable appears …
Cris Luengo's user avatar
  • 6,237
3 votes

How to pass pre-generated values to an anonymous function to speed up a fit?

A named function is declared like this: function out = function_name(in) If it is written in a file of the same name, and the file is on the MATLAB path, then it is accessible from the base workspa …
Cris Luengo's user avatar
  • 6,237
2 votes
Accepted

Selecting indices of a cell array that strcmpi-match the contents of another cell array

Appending to an array INDX46=[INDX46; i;]; is a very slow way of appending to a vector. Instead, do INDX46(end+1) = i;. When appending to the matrix in this preferred way, MATLAB actually extends th …
Cris Luengo's user avatar
  • 6,237
3 votes

Optimizing nested loop for calculating geodesic distance

Just a few tips and tricks to add to David's excellent answer. data = zeros(N,3); for labelVal = 1:N redIdx = idx{labelVal}; greenIdx = idx{labelVal}+numRows*numCols; blueIdx = idx{la …
Cris Luengo's user avatar
  • 6,237
4 votes
Accepted

Applying correction to a time series in Matlab

There is really nothing wrong with using a loop in MATLAB. For decades, they have been teaching us to vectorize our code. But in recent years the differences between vectorized code and the equivalent …
Cris Luengo's user avatar
  • 6,237
1 vote

Getting maximum values in array

There is a sub-field in image processing called Mathematical Morphology. The operation you are implementing is a core concept in this field, called dilation. Obviously, this operation has been studied …
Cris Luengo's user avatar
  • 6,237
2 votes
Accepted

Kernel based conditional increments of many stochastic processes

In regards to performance, I don't immediately see any huge gains to be had. It might be possible to vectorize some operations, but the opportunities are not immediate obvious. …
Cris Luengo's user avatar
  • 6,237
1 vote

Algorithm which finds the count of values are smaller to the right than the current one (in ...

Assuming that the lists always contain small integers, it is possible to sort in O(n) rather than O(n log n). This is called “histogram sort”. In short, you count how many of each integer is in the ar …
Cris Luengo's user avatar
  • 6,237
3 votes

Implementation of a multi-dimensional array as a single memory buffer

I don’t agree with the answer by G. Sliepen. You created a multidimensional array specifically to work with numbers. T is a standard numeric type that doesn’t have a constructor or destructor. It is p …
Cris Luengo's user avatar
  • 6,237
1 vote
Accepted

Recursion to generate fractal

Though MATLAB allows to expand the size of a matrix by assigning to elements outside its bounds, it is always best to preallocate the array to its final size. The for m=1:k loop has a lot of repeated …
Cris Luengo's user avatar
  • 6,237
7 votes

Identify distance degeneracies on square and hexagonal lattices

The core algorithm is this: integers = range(1, nmax+1) pairs = list(product(integers, repeat=2)) pairs = [(a, b) for (a, b) in pairs if a >= b] dict_hex, dict_square = get_dicts(pairs) # loops over …
Cris Luengo's user avatar
  • 6,237
2 votes
Accepted

Terminal Graphical Visualizer, using a queue of different matrices

Don't use std::endl Just output \n for a newline. See here. std::size_t The C++ standard defines std::size_t, not size_t. const placing I personally prefer type const& over const type&. Types are read …
Cris Luengo's user avatar
  • 6,237
7 votes

Algorithm "sort except zero"

I would suggest you use NumPy for anything that manipulates collections of numbers of the same type. A NumPy array is a more efficient container than a list in this case, an the package contain a larg …
Cris Luengo's user avatar
  • 6,237

15 30 50 per page