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.

learn more… | top users | synonyms

0
votes
0answers
6 views

Base conversion error in matlab code [migrated]

I created the following simple matlab functions to convert a number from an arbitrary base to decimal and back this is the first one ...
3
votes
1answer
47 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
47 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
85 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 ...
1
vote
0answers
25 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
28 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
39 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
36 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: ...
0
votes
1answer
123 views

My Python code (for creation of MxM matrix) is much slower than my 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 ...
0
votes
0answers
237 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
375 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
108 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
89 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
65 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? ...
2
votes
1answer
62 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
491 views

How to speed up this k-nearest neighbors code?

I have implemented kNN (k-nearest neighbors) as following, 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. Could ...
2
votes
3answers
64 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
73 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
72 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
2answers
63 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
504 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
363 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. ...
2
votes
1answer
829 views

Matlab - 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, ...
2
votes
2answers
134 views

Matlab: Can this triple loop be simplified or eliminated

Matlab profiler throws this horrible bottleneck which is called 700000 times: ...
0
votes
1answer
2k views

2D convolution in matlab

...
6
votes
2answers
923 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 ...
5
votes
2answers
339 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
314 views

how to improve this matlab code using homogeneus coordinates to rotate a matrix?

Currently, I have this code snippet, but it's a little bit slow: ...
3
votes
1answer
115 views

how to get B+ matrix (warshall algorithm) in matlab?

Pseudocode: ...
5
votes
1answer
141 views

How to speed up this following code

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: ...
3
votes
1answer
160 views

Calculate FFT from windowed time-based signal

I have a time-based signal (Raw signal) sampled at 6 MHz and need to analyze it in freq. domain. I'm learning DSP and this is very first time I work with DSP. Could you please help to check if this ...
1
vote
1answer
425 views

Computing the sum of squared differences of the concentration profile

About Data: I have a 3D data (100x100x20) of space and time (c) where first 2 dimensions are concentration values along space while 3rd dimension contains ...
2
votes
1answer
265 views

Is this a valid usage of structure assignment in C?

Q: Please comment on the usage of structures and structure assignment operations in C I am working on converting a MATLAB program to C using BLAS and LAPACK for linear algebra support. The MATLAB ...
2
votes
2answers
862 views

MATLAB and Armadillo, hints on translating

i'm rewriting some Matlab code to c++ using armadillo, a libs for linear algebra. really good libs, IMHO. but i had to translate some matlab construct because armadillo isn't matlab. i want to share ...
3
votes
1answer
528 views

Generate graph in Matlab

I use this Matlab code: ...
2
votes
1answer
6k views

Matlab code demonstrating use of fft (Fast Fourier Transform)

I posted the following Matlab script in response to a question on Signal Processing. Here is the questions with my answer. I am looking for comments on how to make this code more instructive for the ...
1
vote
1answer
271 views

how I can change this multi-loop to reduce the computation time in Matlab

how I can change this multi-loop to reduce the computation time? A is a matrix (5x10000) with the fifth line contains values ​​between 1 and 50 corresponding to different events of an experiment. My ...
2
votes
1answer
139 views

Is there a way to reduce the computation time in this Matlab program?

Is there a way to reduce the computation time in this program that eliminates the columns of a matrix A if for a given column the element of line 4 is equal to the element in row 5: ...
2
votes
1answer
466 views

how to reduce the computation time for this program matlab?

I started this program for five hours and it has not yet completed. I wonder if we can make changes to reduce the computation time. I use several for loop and this greatly increases the computation ...
3
votes
1answer
105 views

An efficient way to do a series of product

Ax, Ay, Az: [N-by-N] B=AA (dyadic product) It means B(i,j)= [Ax(i,j);Ay(i,j);Az(i,j)]*[Ax(i,j) Ay(i,j) Az(i,j)] B(I,j) : a 3x3 matrix. One way to ...
3
votes
1answer
826 views

Code's optimization and speeding up (Legendre's polynomials and functions) in Matlab

I would like to improve this function to reduce the run time and optimize it. ...
4
votes
1answer
238 views

Speed up for loops _ Set of linear equations

I have N^2 matrixes. Each one is a 3x3 matrix. I want to concatenation them to a 3Nx3N matrix. I know that the big matrix is symmetric. Evaluation of whole 3x3 matrixes are time consuming so I want to ...
3
votes
3answers
423 views

MATLAB 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 ...