# Tag Info

Accepted

### Benchmarks of various scientific programming languages for theoretical modelling

I started with the Julia code you had and also got ~20 seconds, so I think my timings are similar to yours. Let me give a step by step breakdown on how to do this. To start, notice that if you are ...
Accepted

### Why/How is Matlab's circshift function so efficient?

It's hard to tell what the exact problem is of your code without knowing more about the actual input. Still, here are some generic tips: More threads don't always help ...
• 59.2k

### Why/How is Matlab's circshift function so efficient?

Copying data around is typically not something that can be sped up significantly by multithreading (as already stated in the earlier answer). You can even speed up your MATLAB code by rewriting the ...
• 6,132

### Why/How is Matlab's circshift function so efficient?

So first starting with Cris Luengo's post, I optimized the Matlab function a bit more. At first I thought, why include the temporary, but as per the comments and Cris's point about Matlab's indexing, ...
• 357
Accepted

### Running a simulation for all unique combinations of a range of parameters

For a full factorial experiment, you may want to avoid constructing the whole matrix just to get the factor levels for a single experiment, especially if you have a large number of factors and levels ...
• 196

### Optimizing MATLAB Loop

Profiler I want to know where the bottle neck is... Use the profiler to find out, then you will know which specific lines to tackle. Note: the profiler itself will slow things down, so remember to ...
• 181

### Biometric matching score calculator

Regarding the vectorized code: permute can be considered a "Zero-cost operation". Logical operations are performed fastest using ...
• 2,067
Accepted

### Improving Matlab function within big simulation

Vectorization If you look at all the calls to mean, you see that what you are calculating in each loop is a "Cumulative moving average", but in the oposite ...
• 2,067

### Running a simulation for all unique combinations of a range of parameters

NOTE: The code in this answer is rather compact, in order to avoid a lot of scrolling. You might want to put in some additional spaces and line breaks. You know how to do this! Your code looks very ...
• 2,067

### Benchmarks of various scientific programming languages for theoretical modelling

in your MATLAB code, some unnecessary steps can be skipped. Here's a modification of your doStep function that should improve performance quite a bit. Each modif is ...

### A* search in MATLAB

You say getNeighboursByIndx takes 50% of the total time. That means that you should try to reduce either: The number of calls to ...
• 2,067
Accepted

### Optimizing C++ equivalent of Matlab filter function

Few highlights: std::copy(std::begin(z), std::end(z), std::begin(zOut)); To copy input values to overwrite them is just a waste of time. You will overwrite them ...
• 10.5k

### 90 year data simulation in need of performance increase

First off: Indentation! If you have written the code and figure out afterwards that your indentation is wrong / missing / messy, Matlab makes it very easy for you! Ctrl+A followed by Ctrl+I. Simple ...
• 2,067
Accepted

### Matlab Computer Vision

There's a lot going on in this script, but I've tried to cover all of the important parts. Style and conventions: I think your coding style is very good. You're using nice a descriptive variable ...
• 2,067

### Visualizing Newton-Raphson method for finding zeroes of a function

Conventions, coding patterns and readability Overall, your code looks nice! I have never seen a code where you insert a line in the beginning to avoid the script being interpreted as a function. It ...
• 2,067

### Benchmarks of various scientific programming languages for theoretical modelling

Regarding the rpois function, I think the preferred way of simulating a single value from a Poisson distribution with mean λ is ...
Accepted

I'm assuming the data in variable A is calculated somehow in MATLAB, and that you have a matrix A that you want on a tab-...
• 2,067
Accepted

### Counts instances for each category for many Matlab files

You felt it right, there's a lot of unnecessary copy/paste in the first part. Your 5 data structures are similar, and you create a lot of variables to perform the same processing 5 times. I did a ...

### Calculate Mersenne prime numbers in MATLAB

I can comment on multiple things here. But you ask about making the code look cleaner, so I'll start with that Indenting Be consistent with indenting. Indents show the structure of your code. ...
• 6,132

### Finding paths between triangles efficiently in 3D geometry

Efficiency Things that jump out. std::vector<ABPair*> validPathsThread; An array of pointer looks odd. Especially since ABPair is simply a pair of ...
• 95.6k
Accepted

### C++ Eigen/Mex function to perform two pagewise convolutions on a 3D matrix with a simple kernel

This is a great question in most respects, but since the code sample doesn’t compile and can’t be tested, I can only give you a vague and speculative answer. I’ll skip over your Item 1, because I have ...
• 8,099

### Optimizing Matlab Code for Efficient Computation of a Formula with Detrending

First, make sure every line ends with a semicolon. Otherwise, the result will be printed in the command area. Printing 20,000 zeros can take a long time, especially in a loop. Specifically, these two ...
• 2,295

### Srivastava multivariate Fox H function in MATLAB

There are some obvious inefficiencies in the code that I can point out. The profiler shows that most time is spent doing symbolic math. You use symbolic math to compute the product of a series of ...
• 6,132

• 141

### Extract the largest value for each day from a matrix

A few notes: (I implemented this in Octave, so there may be differences between my code and a proper Matlab implementation, but there shouldn't be). First we care about only unique dates, right? So ...
• 21.8k
Accepted

### Horizontally concatenating the entries of two matrices, and padding with NaNs

I see two major way to simplify and speed this up. First, rather than copying a to c at every step of the loop, you can define <...
• 2,404
Accepted

### Parzen window density estimation in MATLAB

Indentation is automatically fixed in MATLAB by marking everything, and do Ctrl+I. The common practice is to have the first level alligned all the way to the left. Click here to see a screenshot from ...
• 2,067
Accepted

### Find first N primes

There are many algorithms that can be used to find the first N primes. I won't comment on the performance of the core algorithm. Your function returns the first <...
• 2,067
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 ...
• 6,132