Questions tagged [matlab]

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.

Filter by
Sorted by
Tagged with
21
votes
5answers
1k views

Benchmarks of various scientific programming languages for theoretical modelling

For a theoretical modelling course for biology students, I am trying to decide which would be the best technical programming language for doing evolutionary simulations in terms of elegance and ...
14
votes
2answers
2k views

A* search in MATLAB

I have implemented A* search in MATLAB, but I am looking for ways to increase the speed and optimize it. I have tried using a priority queue but I found it doesn't work that well, so I am using a ...
12
votes
1answer
167 views

Possible “Angle of Incidence” of an RC tail-dragger plane

I am working for an Aero-Design team and we make RC planes that are capable of humanitarian aid. We wished to make a tail dragger and for stability reasons the "Angle of Incidence" (AOI) of the plane ...
10
votes
2answers
334 views

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

I have written a script which is supposed to call the function at the bottom for each unique combination of values in the parameter vectors. That function is a simulation which I intend to run over ...
10
votes
1answer
2k 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) ...
8
votes
1answer
145 views

Matlab Computer Vision

The code below takes a video as input (a drop onto a fabric surface) and I want it to return the area of the drop. Currently the code works, but I'm no Matlab expert, and wrote it entirely through ...
8
votes
1answer
195 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 100 ...
7
votes
3answers
261 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 ...
7
votes
3answers
5k views

k-nearest neighbors using MATLAB with MEX

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. ...
7
votes
2answers
602 views

Visualizing Newton-Raphson method for finding zeroes of a function

I have created a program to visualize the working of Newton-Raphson method to find the zeroes of a function: newton.m: ...
7
votes
1answer
2k views

Using homogeneous coordinates to rotate an image

Currently, I have this code snippet, but it's a little bit slow: ...
6
votes
3answers
177 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 ...
6
votes
2answers
4k views

Python / Numpy running 15x slower than MATLAB - am I using Numpy effeciently?

Here is some code I wrote in Python / Numpy that I pretty much directly translated from MATLAB code. When I run the code in MATLAB on my machine, it takes roughly 17 seconds. When I run the code in ...
6
votes
2answers
1k views

Drawing random smooth lines contained within a square

I'm trying to write a matlab function that creates random, smooth trajectories in a square of finite side length. Here is my current attempt at such a procedure: ...
6
votes
1answer
442 views

Segmenting brain images (Dicom format) using region-growing algorithm

I have a list of images in a folder where num denotes the index of image and I used num to run the iterations in a "for loop". ...
5
votes
2answers
26k 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 ...
5
votes
1answer
463 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 ...
5
votes
1answer
126 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 ...
5
votes
2answers
91 views

Extract the largest value for each day from a matrix

I have a matrix in which the right-most elements are repeated YYYYMMDD dates in descending order, for example: ...
5
votes
1answer
134 views

Computing the total different between a pixel and its neighborhood

I have C++ code which written for mex in MATLAB. It used to compute the total different between a pixel and its neighborhood (8 neighborhood in my code). The code ran and gave me an expected result. ...
5
votes
1answer
116 views

Mean of the squares of differences for a large matrix

I have tried to obtain speed gains by transferring Matlab calculations to C and call it using .mex. My goal is to operate on a matrix \$B\$ which has roughly the dimension 10000x1000 $$ \frac{1}{\...
5
votes
1answer
97 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 ...
5
votes
1answer
2k views

Function for plotting Julia Set

The Julia set is the set of complex numbers z that do not diverge under the following iteration: $$ z = z^2 + c $$ Where c is a constant complex number. Different values of z reach infinity at ...
5
votes
1answer
170 views

Processing random matrices

I am doing my research about scheduling by using Matlab. I am a new Matlab user and I have a problem with time execution of my following code: ...
5
votes
1answer
38 views

Simple SVM in MATLAB

I'm studying SVMs and wrote a demo in MATLAB (because I couldn't get a quadratic programming package to work correctly in Python). Right now it's simple and can only do linearly-separable cases (...
4
votes
3answers
494 views

Presidential election predictor using matrix-processing

I'm currently working on a project where I am trying to predict a presidential election based on the population density and region of a voter. I wrote a few MATLAB functions to parse the data, but it ...
4
votes
2answers
1k views

Optimizing C++ equivalent of Matlab `filter` function

Minimum working example below. The Matlab filter function filters the input data x using a rational transfer function defined by the numerator and denominator ...
4
votes
1answer
120 views

Biometric matching score calculator

I'm working on a biometric matching system and I would like to have few suggestions regarding vectorizing the following code: ...
4
votes
1answer
178 views

Calculate Mersenne prime numbers in MATLAB

A Mersenne prime is equal to (2^n - 1), where n is an integer. 31 is a Mersenne prime since 31 = 2^5 -1. I need to write a code that calculates Mersenne primes between 1 and 10,000. Lastly I'm not ...
4
votes
2answers
740 views

Iterative Implementation of Towers of Hanoi

Here is an implementation of Towers of Hanoi based on few observed patterns1 from the easier recursive solution: ...
4
votes
1answer
26k 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 ...
4
votes
2answers
88 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? ...
4
votes
1answer
58 views

Vector operations

I want to perform the following procedure: I have two vectors x=[1,2,3] and y=[5,7,9] I want to take first element of ...
4
votes
1answer
66 views

Getting saddle points of a matrix

My homework assignment: Write a function called saddle that finds saddle points in the input matrix M. For the purposes of this problem, a saddle point is defined as an element whose value is ...
4
votes
1answer
2k views

Plotting the Koch Snowflake

The Koch snowflake is a well known fractal. Beginning with an equilateral triangle, a smaller equilateral triangle is placed halfway along each edge of the shape. This process then repeats on each ...
4
votes
2answers
114 views

Vectorizing a polar coordinate conversion loop in a fingerprint-matching process

I am working on a fingerprint matching technique and it takes a lot of computation time to obtain the result. I am trying to implement the matching process given in A Minutia Matching Algorithm in ...
4
votes
1answer
81 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 ...
4
votes
1answer
334 views

Set of linear equations

I have \$ N^2 \$ matrices. Each one is a \$ 3 \times 3 \$ matrix. I want to concatenation them to a \$ 3N \times 3N \$ matrix. I know that the big matrix is symmetric. Evaluation of whole \$ 3 \times ...
4
votes
1answer
118 views

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

I have a small function that gets a vector of N linear indices locations in a matrix and returns N new locations in the same matrix. For each of the input locations, a random angle tet and a distance ...
4
votes
1answer
145 views

Removing undesired points from a mesh

I have a 3D data set made of a certain number of points (x,y,z) that cover a certain region of space. Using the scatteredInterpolant object I can interpolate this ...
4
votes
1answer
77 views

Vectorizing Two Sample Kolmogorov-Smirnov test

I'm implementing the Two-sample Kolmogorov-Smirnov test in MATLAB. I must admit I know very little of formal statistics and was simply trying to implement the description in wikipedia's page. Right ...
4
votes
2answers
3k 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: <...
4
votes
1answer
193 views

Shortest distance from point to line segment in 3D

This function returns the shortest distance from a 3D point P to a line segment defined by two 3D points A and B. It projects P onto the line, then checks if this projected point lies between A and B. ...
4
votes
2answers
52 views

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

I have a Matlab structure with several fields, 3 of which are interesting here: ...
4
votes
1answer
89 views

Wavelet decomposition of images

I am working on wavelet decomposition and found a formula for it and wrote it by myself for computation. The formula is: $$I_{LH}(i,j) = \sum_{p=1}^{N_L} \sum_{q=1}^{N_H}\ L(p)\ H(q)\ I(i+p, j+q)$$ ...
4
votes
1answer
374 views

Matlab IIR filter implementation

I need to implement the Matlab filter(b,a,x) function in Java. Before I do this, I would like to rewrite the function in Matlab before translating into Java. So far,...
4
votes
0answers
99 views

Neuroscientific testing

I have written the code below for the following experiment: Subjects get simultaneous stimulation of left and right thumb and have to tell which one was stimulated "stronger" (with higher intensity, ...
4
votes
0answers
706 views

Reading cell array of vectors with h5py

I have a data stored in .mat files, each .mat contains a cell array of vectors of length ~70. I'm trying to read these .mat files in to Python with h5py, but reading just 1000 cells takes about 7 ...
4
votes
0answers
2k 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; ...
3
votes
3answers
107 views

Finding paths between triangles efficiently in 3D geometry

An update to this post can be found here I've been writing some functions used to find paths between two types of triangles - alphas and betas. Alphas are triangles that have been in a zone we ...