MATLAB is a high-level language and interactive programming environment developed by MathWorks. It is the foundation for a number of other tools, including Simulink and various toolboxes that extend the core capabilities.
1
vote
0answers
36 views
Function that reorders the columns of a matrix
The objective: Given an m by n matrix, I have written a function in Matlab that reorders the columns of the matrix to output linearly independent columns; other/redundant columns. Basically, it just ...
0
votes
0answers
13 views
Implement Chambolle dual formulation method in matlab
I would like to implement an Chambolle dual formulation method. The method can be summarize as following
This is my implementation in matlab. However, it does not give true result (but combine ...
2
votes
1answer
34 views
Searching for log entries in SQLite that involve a particular IP subnet
This reads a huge database (SQLite) and extract any IP address similar to ip_base:
...
3
votes
1answer
85 views
Currying in Matlab
As MATLAB has a hard maximum of 10 input arguments it's possible, but ugly, to implement a curry function in this manner:
...
0
votes
1answer
45 views
Matlab to C++ percentile clipping
I have a 2D matrix in Matlab and I want to convert the Matlab code into C++.
In C++ I have int* channel_gr. The commented code is the original Matlab code.
Is ...
0
votes
1answer
56 views
Plotting a trigonometric function appears to be too slow
This calculates the mobility and it's derivative of one element. If I calculate with 1 value of w, it's very fast.
...
2
votes
1answer
46 views
Dealing with input and output in Matlab
I just wrote a program which performed some elementary set operations as you can see below. It's the first time I have used input and output of text files so I am mainly looking for critique on that, ...
1
vote
0answers
29 views
Matlab bins with two features: calculation and plotting
I have the following code in Matlab, which is supposed to do what I asked in this SO question. The idea is to:
Divide the temperature deadband of each agent (they are different between agents) into ...
2
votes
0answers
213 views
fftshift implementation for OpenCV
I'm trying to implement fftshift from matlab for OpenCV. Can you please review the correctness of my algorithm? Have I missed something? Also, is there a better and faster way to do it?
...
1
vote
0answers
175 views
Simple Priority Queue
I am trying to implement A* search on a grid in MATLAB. I am currently using a priority queue class I found here, but it's a bit slow. I tried to write this simple priority queue class in MATLAB:
...
0
votes
0answers
40 views
4
votes
1answer
88 views
Large Matrix Square Difference Means
I try to transfere Matlab calculation to C and call it using .mex for speed gains. My goal is to perform for a matrix \$ B\$ which has roughly the dimension 10000x1000
\$
...
1
vote
1answer
87 views
Optimize matlab triple for loop
I have a large matrix samples, I want to make another matrix sampleProb which is the same size, but modified as below:
...
4
votes
1answer
45 views
Implementation of Logistic Regression
Is this kind of vectorized operations the most efficient way to do this in matlab? Any critics about my code? Am I doing something wrong (i tested several times, I think it works). Notice that I use J ...
3
votes
1answer
33 views
Integrate the product of four infinite series functions
I wrote the following code to integrate the product of four functions.
Two of the functions are hypergeometric functions and the other two are incomplete gamma functions. I have written each function ...
1
vote
0answers
35 views
Iteratively process an identically named file all subdirectories and plot analysis to root directory
This script can successfully go through all of the subdirectories in a root directory, and then process a specific file that exists in all of them and output the file in the root directory as a .png ...
4
votes
1answer
71 views
Vectorization for temperature simulation
I'm new to Matlab and I would like to know tips in order to reduce the processing time of such program. The scheme of the actual code is very similar to typical C++ code and I would like to vectorize ...
2
votes
0answers
71 views
Speeding up loop-rich Matlab function to calculate temperature distribution
I would like to speed up this function as much as possible in Matlab.
This is part of a bigger simulation project, and as it is one of the most called functions within the simulation, this is crucial.
...
3
votes
2answers
87 views
Improving Matlab function within big simulation
I have a very big Matlab simulation project in my hands, which I wanted to optimize, since I'm running it many times to tune parameters and the like.
Using Matlab's ...
1
vote
1answer
60 views
Improving excution time for list and sampling in Python
Here is my code for generating edge list based on Price model algorithm. I think there have two points to reduce execution time:
use proper data type
use faster random sampling
Originally, I used ...
10
votes
1answer
764 views
Counting Words in Files - MATLAB style
For my Matlab class I'm taking, I was given the task to write a function ReadAndCountWords that takes in the name of a text file (specifically from this zip file) ...
3
votes
1answer
1k views
Run length encoding of vectors in MATLAB: looped version and vectorized version
A project I'm working on requires something akin to run length encoding on a vector in matlab. The data is in the form of a numeric vector, and the output is in the form of two vectors, ...
1
vote
0answers
41 views
Simple class container for hdf5 files
I implemented a simple class container for hdf5 files in matlab.
The situation is as follows. Measurement data is saved in hdf5 ...
1
vote
0answers
183 views
Efficient C Code Alternative to MATLAB's im2col
The function im2col in MATLAB is very useful to vectorize Patch based Image Processing algorithms.
The problem is the function isn't optimized and doesn't use C ...
1
vote
2answers
125 views
Using brute force to find an energy optimal path for a given amount of time
The code below implements a brute force method to find an energy optimal path for a given amount of time t_aim using recursion (the recursion function is ...
4
votes
2answers
5k views
Trapezoidal rule to approximate the integral of x^2
I've implemented the trapezoidal rule to compute the integral for a function \$x^2\$. I would like to see another style of the same code. It seems Matlab hates for a matrix to be expanded without ...
2
votes
2answers
115 views
90 year data simulation in need of performance increase
I developed some code for my masters project that will simulate 90 years daily data using 1000 different data sets. The code is working fine and gives the correct output that I wanted but the ...
2
votes
0answers
83 views
Kullback-Leibler (KL) distance between inside and outside contour code
I am trying implement the distance measurement between two distributions. The detail is described in here and input image . Let short summarize the idea of the paper:
The input image is divided ...
4
votes
1answer
167 views
Vectorize Matlab sum
I have the following Matlab function:
function [res] = a3_funct(x)
res = 0;
for i = 1:size(x,1)
res = res + abs(x(i))^(i+1);
end
end
It's ...
3
votes
0answers
594 views
Satellite orbit simulation in Matlab using Runge Kutta 4
I have a satellite orbit simulation in Matlab (Using Runge Kutta 4). It seems ugly and I don't know how to fix it.
fx.m file:
function v = fx(t,x,vx)
v = vx;
...
8
votes
1answer
147 views
Verifying boardgame mathematics with MATLAB
I recently bought this math-based boardgame for my little cousins, and am now trying to verify its design with some MATLAB code. The relevant parts of the game are:
A board with numbers from 1 to ...
2
votes
0answers
34 views
Avoiding boundaries if-cases when filtering image matrix
I have the following MATLAB Code which I want to optimize.
It's related to an image matrix (2D) which I want to filter.
Though it is MATLAB code, the same problem would arise in C code.
The problem ...
1
vote
0answers
48 views
Why does lu-factorization make my program slower?
I'm trying to calculate the smallest eigenvalue of the matrix A by using the "inverted exponentiation method" (see the code). I manage to find the smallest eigenvalue, but when I try to optimize the ...
2
votes
1answer
47 views
Less For, more MATLABesque?
I have written a piece of MATLAB code that (hopefully) calculates CECT. I have two matrices of psychophysiological measures - one for brain data, one for heart rate; both are of the format epochs * ...
3
votes
1answer
56 views
Using the Return Value of a Function to Select an Element in a Struct Array
I'm learning MATLAB (still trying to "think in vectors") and have the following piece of code:
...
1
vote
1answer
197 views
Creation of MxM matrix: Python version much slower than Matlab version
I have written the same code in Python (NumPy) and in Matlab, and I tried to use the same structure for both language and follow the same procedure. Now my problem is that when I run my code in Python ...
-1
votes
1answer
358 views
Stochastic gradient descent squared loss
I have implemented stochastic gradient descent in matlab and I would like to compare my results with another source but the error I am getting is higher (I am using squared error). I am worried I am ...
4
votes
1answer
7k views
K-nearest neighbours in MATLAB
I implemented K-Nearest Neighbours algorithm, but my experience using MATLAB is lacking. I need you to check the small portion of code and tell me what can be improved or modified. I hope it is a ...
2
votes
1answer
660 views
Parsing MWNumericArray to C# code optimization
This is my function returning matrices from Matlab. This code run very slowly.
I was trying to use Parallel.For in-order to run it in parallel threads but I got ...
2
votes
0answers
100 views
Increasing speed of parity check matrix
The code runs fine and takes 100s to complete it for 5 iteration. I need to reduce it to take less time with the same number of iterations.
h = 324 by 648 matrix
The code is that of FFT Belief ...
4
votes
2answers
73 views
What's the fastest way to get the points I want out of a huge blob?
In MATLAB I have a set of 5393280 points in the form of a decimal-valued vector (x,y,z). How do I represent them in a way that I can quickly collect all the points within some rectangular x-y domain?
...
1
vote
1answer
84 views
How can these if-else statements be made more efficient?
I am using the cURL tool in MATLAB 2013b with Ubuntu to download a whole bunch of files. The files have one of three possible versions: 1.0.0, 2.0.0, or 2.1.0. Using the HTTP, I first check the ...
6
votes
3answers
3k views
Speeding up this k-nearest neighbors implementation
I have implemented kNN (k-nearest neighbors) as follows, but it is very slow. I want to get an exact k-nearest-neighbor, not the approximate ones, so I didn't use the FLANN or ANN libraries.
...
2
votes
3answers
94 views
Is this a valid way of computing autocorrelation?
I am a beginner in Digital Signal Processing and I was trying to compute and plot an autocorrelation.
I've wrote this piece of code:
...
1
vote
1answer
80 views
Speeding up repetitive initialisation with structured data?
I need to speed up this code: it creates a multilinear function. I considered the below methods but no idea which with the largest benefit.
replacing dummy variables with things such as anonymous ...
2
votes
0answers
82 views
Fitness function
I have a fitness function, where inputs x1 to x14 have values between 1:4. Is there a way to make this more efficient? Any ...
1
vote
3answers
79 views
Using matlabpool: Is my embedding correct?
A general question: For using matlabpool, I write the line
matlabpool open local 12;
as the first line in my code and the line:
...
1
vote
1answer
981 views
Matlab - Fastest way to parallel read many files line by line?
I have a few hundred files in a directory that I need to read in parallel. Namely, the files that have the same name, but different file extensions (.a and .b), but they're pretty much plain text ...
1
vote
2answers
697 views
Rational Approximation for e with Matlab
I've written a program that calculates the best rational approximation for e with a 1, 2, 3, 4, 5, and 6 digit denominator respectively (on Matlab). For a 5-digit denominator it takes about a minute. ...
3
votes
1answer
2k views
Build a combinatorial matrix from two vectors
I want to define a matrix of values with a very simple pattern. I've achieved it with the code below but it's ugly - very difficult to read (I find) and surely not as optimal, in terms of performance, ...