Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 151754

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.

9 votes

Why/How is Matlab's circshift function so efficient?

You can even speed up your MATLAB code by rewriting the inner loop: for nx=1:xSize DataTemp(:,nx)=circshift(Data(:,nx,nT),nShift(nR,nx)); end RawDataKK(:,nT,nR)=sum(DataTemp,2); Here you are copying … Regarding the code style: Even though it is really common to see MATLAB code with very few spaces in it, adding spaces around operators and after commas really helps readability. …
Cris Luengo's user avatar
  • 6,237
5 votes

Srivastava multivariate Fox H function in MATLAB

MATLAB has a numeric gamma function. Simply leaving out the call to sym in your code should reduce the computational cost of your code by a few orders of magnitude. … A struct in MATLAB is very much like a cell array, but the indexing is done with a name instead of a number. …
Cris Luengo's user avatar
  • 6,237
2 votes
Accepted

considering only the instants of trading with the relative price avoiding stale returns

To speed up code you have to start with two things: Pay attention to the warnings that the MATLAB Editor gives you: Four lines have red squiggles underneath, hovering over them says "Variable appears … In the MATLAB Editor, there is a button "Run", if you click the bottom part it expands into a menu. The top options here is "Run and Time". …
Cris Luengo's user avatar
  • 6,237
3 votes
Accepted

Simple validation and mathematical function in MATLAB

The function Triangle() is clearly a script that you turned into a function. I personally don't like putting clc, clear and close at the top of my scripts, but I see this a lot, and it's not a terribl …
Cris Luengo's user avatar
  • 6,237
2 votes

Performance Optimization in Matlab

Instead of A = Data{n,3}(18:length(Data{n,3}),1); do A = Data{n,3}(18:end,1); Repeatedly extending an array Yes, you can extend an array in MATLAB. … Not using vectorized operations Loops are rather fast nowadays in MATLAB, so much so that vectorizing an operation (removing the explicit loop in favour of vectorized operations) is not guaranteed to improve …
Cris Luengo's user avatar
  • 6,237
2 votes
Accepted

String / Char Vector Concatenation Performance Comparison in Matlab

It was first posted on the MATLAB File Exchange by senior MATLAB developer Steve Eddins (here is his blog post at the time). … I would recommend against explicitly setting the renderer, and let MATLAB pick the best one for the graphics you're displaying. …
Cris Luengo's user avatar
  • 6,237
1 vote
Accepted

No Reference Image Quality Assessment for Video in Matlab

MATLAB Editor warnings On these two lines, the MATLAB Editor gives a warning "Use of brackets [] is unnecessary". … Note that if we name the input and output variable the same (here frame), and when calling the function we use the same variable as both input and output (videoFrame in your code), then MATLAB will optimize …
Cris Luengo's user avatar
  • 6,237
2 votes
Accepted

Cholesky decomposition

MATLAB first included a JIT (Just In Time) compiler in 2006 I think, and it has been steadily improving over the years. … In MATLAB R2015b, they introduced a completely new JIT, and since then the difference between trivial loops and vectorized code is no longer important, and a more complex loop is oftentimes faster than …
Cris Luengo's user avatar
  • 6,237
1 vote
Accepted

Recursion to generate fractal

Though MATLAB allows to expand the size of a matrix by assigning to elements outside its bounds, it is always best to preallocate the array to its final size. … It is common in MATLAB code to not use spaces, but I think code is more readable with spaces in it. Especially around the = assignment operator. …
Cris Luengo's user avatar
  • 6,237
1 vote
Accepted

Mean and variance of element-wise distances in a set of multi-dimensional arrays in Matlab

My only comment here is that AIED = AverageIntraEuclideanDistancesPar(Collection) VIED = VarIntraEuclideanDistancesPar(Collection) computes the average twice, since VarIntraEuclideanDistancesPar also …
Cris Luengo's user avatar
  • 6,237
1 vote
Accepted

Calculate distances between two multi-dimensional arrays in Matlab

Your test cases don’t test the error condition handling: if size(X1)~=size(X2) fprintf("Sizes of inputs are not equal!\n"); return; end In the case of two inputs with different dimensionality …
Cris Luengo's user avatar
  • 6,237
1 vote
Accepted

Finding max number and location in multidimensional array in Matlab

This syntax is equal to the old-fashioned [M,I] = max(A(:)), which will work even in 20-year-old versions of MATLAB. …
Cris Luengo's user avatar
  • 6,237
2 votes
Accepted

Batch generating histograms of images in Matlab

There's not a whole lot of things to comment on this code. My biggest gripe with it is the comparison of a boolean value with false. I see this a lot, it is a common "mistake". There always exist the …
Cris Luengo's user avatar
  • 6,237
2 votes
Accepted

Three-dimensional DCT spatial frequency components illustration

First I'll discuss some MATLAB syntax and style improvements. OutputCollection{x, y, z} = {Output}; This puts Output into a 1x1 cell array, and assigns this cell array into the larger cell array. … Simpler would be: cubeColor = [1 1 1] * input_array(x, y, z); plotcube([1 1 1], [x - 1 y - 1 z - 1], alpha, cubeColor); The MATLAB Editor highlights this line: IDCT3DOutput(n1+1,n2+1,n3+1)=sm; and …
Cris Luengo's user avatar
  • 6,237
0 votes
Accepted

Matlab vs C: Tensorproduct or Vec-trick (multiple times)

I created a matrix X as suggested in the math, and vectorized it using reshape, so I could compare the results with an explicit implementation in MATLAB. … If I would input the wrong matrices, the MEX-file (and usually all of MATLAB) would crash. …
Cris Luengo's user avatar
  • 6,237

15 30 50 per page