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
0
votes
0answers
14 views

Matlab code to show matrix in upper triangular form [closed]

I am creating a MATLAB function that would change the input matrix into a triangular form. The The code script is shown below. However, the code is neither efficient nor correct. ...
4
votes
0answers
144 views

Cross-Entropy Minimization - Extreme Code Performance

I'm working on a multivariate cross-entropy minimization model (for more details about it, see this paper, pp. 32-33). It's purpose is to adjust a prior multivariate distribution (in this case, a ...
2
votes
0answers
21 views

Implementation of calculation of gamma for RBF SVM

I have implemented the calculation of gamma value for RBF SVM as described in Liu et al (2012) [https://ieeexplore.ieee.org/abstract/document/6246300]. Here's a snapshot of the example from the paper: ...
1
vote
0answers
46 views

Custom Model intended to be used for Curve Fitting. Vectorization vs For Loop and jit numba capabilities

I am new to community and please pardon me if I didn't provide information as intended. This code is supposed to be creating a custom model which will be used with ...
4
votes
2answers
75 views

Optimizing nested loop for calculating geodesic distance

I segmented an image into N superpixels and constructed a graph based on that in which each superpixel is considered as a node. The information about neighbor superpixels is stored in ...
2
votes
1answer
79 views

Vectorizing equations for fsolve

I have a system of 49 equations and 49 unknowns (\$x_{1},...,x_{49}\$). All equations have the following form. \$x_{s}\sum_{r=1}^{R}\sum_{t=1}^{T}a_{s,t}b_{rs,t}=\sum_{r=1}^{R}\sum_{t=1}^{T}a_{r,t}...
1
vote
1answer
73 views

My implementation of the Union-Find data structure in MATLAB

I was assigned the connected components labeling (CCL) algorithm and in order to implement the CCL algorithm I first had to implement the Union-Find algorithm. This is my try at it, any review and ...
3
votes
2answers
54 views

Reduction of time for the code of sorting RGB and Depth images according to timestamp values

I have RGB Images, Depth images and OpenPose Images(generated from RGB Images). The number of RGB and Depth images are different so I have to find the exactly which RGB images corresponds to which ...
1
vote
0answers
32 views

Calculating the term of dfdeta [closed]

I am trying to improve the time running of this code. Some dummies variable is defined and it is just some part of a lot of lines of code, but I tried it with dummies variables. It takes too much in ...
2
votes
1answer
185 views

My custom implementation of MATLAB's imdilate

I have been assigned to implement the morphological dilation operation without using MATLAB's imdilate, and I came up with the following solution: ...
1
vote
0answers
71 views

MATLAB / vs Python np.linalg.solve, heat diffusion, Why Python is slow? [closed]

I am solving a simple 1D steady heat question using spectral method. I am a long time MATLAB and Mathematica user and trying to learn Python. I compare only linear solving times and Python is way ...
4
votes
1answer
48 views

Kernel based conditional increments of many stochastic processes

I have written this function is part of a research project that involves analyzing time-series data from stochastic processes. We have a small number (from 1 to 3) of independent observations of a ...
2
votes
0answers
21 views

Simulation of splitting particles (MATLAB - Fortran) [closed]

I'm trying to write a code where a charged particle (charge=+20 called dimers), after a certain time, will split into a neutral particle and a smaller charged particle (charge=-10 called monomer). I ...
3
votes
2answers
64 views

Finding paths between triangles efficiently in 3D geometry #2

This post is an update of the one from here. I've updated the code and a couple pieces of the post itself. I've been writing some functions used to find paths between two types of triangles - alphas ...
3
votes
3answers
116 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 ...
4
votes
1answer
743 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 ...
5
votes
1answer
80 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 (...
3
votes
0answers
62 views

Optimising multiplication of matrix rows with matrix slice/page

I've recently vectorized most of the code for an optimization problem but this one still eludes me. As the procedure and not the actual values are important here, I have replaced the original matrices ...
4
votes
1answer
513 views

Artificial Neural Network Classifier in Matlab

I am trying to build a neural network classifier. I have created a neural network with 1 hidden layer (25 neurons) and 1 output layer (1 neuron/binary classification). The dataset I am using has the ...
2
votes
1answer
63 views

Applying a function to columns of two matrices producing their combinations

I made a short snippet for applying a function f that takes two arguments (vectors) to columns of two matrices producing all possible combinations of those columns. ...
3
votes
1answer
308 views

Draw common tangents to two circles interactively in MATLAB

Requirement After a user draws two circles with their mouse successively, the program should draw all common tangents, if any, to them. Here is my implementation ...
4
votes
1answer
63 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 ...
2
votes
1answer
94 views

Applying correction to a time series in Matlab

I face a computation efficiency problem. I have a time series of a non-monotonically drifting variable, that is measurements of objects going through a machine (where the measurement is made) in a ...
4
votes
1answer
248 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 ...
3
votes
1answer
68 views

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

In Matlab I am using the combination of fit and fittype function (from the curve fitting toolbox) to fit a signal using an ...
5
votes
1answer
630 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,...
1
vote
1answer
72 views

vectorize 2D gradient with spatially varying bins

The following code takes in some values ssh and solves the equations for the geostrophic motion (slide 8 here). The main part of the code is the computation of the ...
6
votes
1answer
130 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 ...
1
vote
2answers
696 views

Array splitting in sub-arrays of consecutive elements

I want to split an array in sub-arrays of consecutive elements. For example, for the array: a=[1 2 3 6 7 9 10 15] I want an output ...
2
votes
0answers
3k views

Matlab Code for Convolutional Neural Networks

I am using Matlab to train a convolutional neural network to do a two class image classification problem. I have an imbalanced data set (~1800 images minority class, ~5000 images majority class). As I ...
3
votes
2answers
369 views

Spectrum Analysis with Discrete Fourier Transform

Here is a simple implementation of the Discrete Fourier Transform: myFourierTransform.m ...
1
vote
0answers
164 views

Matlab and WidowX robot arm communication and control

For a class, we needed to control the WidowX arm from Trossen Robotics from Matlab and get as real-time of a feedback as possible. So I came up with a code for the Arbotix Robot-controller which is ...
1
vote
1answer
73 views

Extracting data from meshgrid output

I am trying to extract data from meshgrid output where zCs is 1000 x 1000 matrix of z values which is produced from meshgrid of s using bin2mat. s is a struct which has x, y, z data. res is 1000. ...
4
votes
2answers
885 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: ...
1
vote
1answer
842 views

Find first N primes

Here is code that returns the first N prime numbers: ...
1
vote
2answers
129 views

Exporting Matlab Figures as PDF with a Minimal Amount of Whitespace for use in LaTeX

About this code This Matlab function takes in the handle of a figure and exports a PDF containing a vector image of the plot. The caller of this function can opt to even remove the axes if he or ...
2
votes
0answers
35 views

Identifying local peaks among some 2D points

The following MATLAB code takes in multiple peak coordinates and heights and eliminates lesser peaks that are within a certain distance threshold of the highest peak of the vicinity. Is there a better ...
4
votes
1answer
380 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. ...
-1
votes
2answers
236 views

Optimizing MATLAB Loop

I have the following code in matlab and since the matrices are huge it takes more than one hour. I wanted to know where the bottle neck is and if there is any way to optimize this and make it faster. ...
4
votes
1answer
223 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 ...
1
vote
0answers
1k views

Convert Java data to Weka-friendly format without using ARFF

recently I've been working on machine learning with Java and Weka, and while I found the .ARFF format easy to understand (you just need an .ARFF file and Weka will do the rest :P), sometimes the ...
1
vote
0answers
73 views

AABB Intersections with Space Partitions, A Sample Code Performance and Reliability

I have originally written the following Matlab code to find intersection between a set of Axes Aligned Bounding Boxes (AABB) and space partitions (here 8 partitions). I believe it is readable by ...
4
votes
2answers
58 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: ...
1
vote
2answers
1k views

Image Compression Using the Singular Value Decomposition (SVD) with MATLAB

I'm new to both linear algebra and MATLAB. I need help with this code with the objective of compressing image using the Singular Value Decomposition (SVD). The code is currently working, if I run with ...
12
votes
1answer
217 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 ...
1
vote
0answers
518 views

Implementation of Multiclass Perceptron

The following text is from Hal Daumé III's "A Course in Machine Learning" online text book (Page-41). I implemented the following: Is the implementation correct? ...
1
vote
0answers
67 views

Multi-layered Perceptron

Solution: Generate Training Set ...
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, ...
3
votes
0answers
95 views

Classifying test data into several classes

The following code is to classify the test data into several classes: ...
3
votes
1answer
2k views

Parzen window density estimation in MATLAB

This was my C# implementation of Parzen Window Density Estimation. The following is my implementation of the same in Matlab: parzen.m ...