Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
0answers
16 views

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 hidden neurons) and 1 output layer (1 neuron/binary classification). The dataset I am using ...
1
vote
1answer
38 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. ...
0
votes
0answers
26 views

Smoother animation with linkprop in matlab figure

So I gone through my code and truncated it as much as possible to get to the meat of the problem. My code contains GUI functions and variables to allow for easy building of the animations. As my main ...
3
votes
1answer
89 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
43 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 x and then add each element from y to it, then I want to take second element ...
2
votes
1answer
84 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
114 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
45 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 ...
3
votes
1answer
113 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, writing out all the coefficients ...
1
vote
1answer
39 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 ...
4
votes
1answer
113 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
317 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
1k 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
111 views

Spectrum Analysis with Discrete Fourier Transform

Here is a simple implementation of the Discrete Fourier Transform: myFourierTransform.m ...
1
vote
0answers
93 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
62 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
520 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
235 views

Find first N primes

Here is code that returns the first N prime numbers: ...
1
vote
2answers
120 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
33 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 ...
0
votes
0answers
43 views

Iterating random motion with constant drift velocity on random times in random direction

I am working on simulating random motion of particles, there are two times exponentially distributed randomly defined as t1 and t2. For time less than t1 particle is in free random motion while for ...
4
votes
1answer
155 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
211 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
117 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
775 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
63 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 ...
3
votes
1answer
42 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
814 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 ...
11
votes
1answer
153 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
329 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
56 views

Multi-layered Perceptron

Solution: Generate Training Set ...
5
votes
0answers
98 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
89 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 ...
4
votes
1answer
1k 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 ...
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 ...
1
vote
2answers
131 views

Locate a number in an array with a special ordering

Below are two examples of arrays (with a special ordering with odd numbers on one side, and even number on the other side) I have, with some given len: ...
1
vote
1answer
81 views

Counts instances for each category for many Matlab files

This is for machine learning. I have 5 matlab files: AWA, REM, S1, S2, SWS. Each one has 2 arrays: x and y. ...
4
votes
1answer
84 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
2answers
986 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 ...
2
votes
1answer
78 views

Locate a number in an array with ascending even and descending odd entries

Below are two examples of arrays I have, with some given length: For some value z, I want to find the column the value is in. ...
3
votes
1answer
444 views

Exporting a table with header and subheader

I have an array matrix, for example A(3,3), I want to make a table with header names like, ['force','mass','acceleration'], the second row contains the units (subheader), ['N','Kg','m/s^2'], and the ...
2
votes
0answers
84 views

Making interpolations in a 4D matrix

I have Matlab code that is very inefficient and I need to run it several times. The code is basically a big parfor loop which I guess there is almost impossible to ...
10
votes
2answers
332 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 ...
1
vote
1answer
114 views

Finding shortest distance between a point and a surface using Lagrange Multipliers

I am new to Matlab. Now I need to find the shortest distance between a given point to a surface, which is describe with a function. I am planing to implement the method described in the link below ...
4
votes
1answer
71 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
1answer
825 views

Matlab implementation of Needleman-Wunsch algorithm

This code (an implementation of the path finding Needleman-Wunsch algorithm), given two sequences, correctly aligns and calculates the similarity of them. For example, given two sequences: AAA,CCC ...
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 ...
1
vote
1answer
123 views

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

I have two matrices a and b that have, on each line, some values (null or not) and then a bunch of zeros at the end. I want to ...
5
votes
2answers
90 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: ...