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.

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
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
3 votes
Accepted

Simple Priority Queue

If we let MATLAB do the memory management (MATLAB will double the storage when appending elements to an array, and does so much more efficiently than this user's code), and store the priorities in a numeric …
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
4 votes
Accepted

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

comparisons: % original code new_r = mod(new_r,A)+1; % alternative I = new_r>A; new_r(I) = new_r(I)-A; I = new_r<1; new_r(I) = new_r(I)+A; This is actually slower in Octave, but it's possible that MATLAB
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
1 vote
Accepted

My implementation of the Union-Find data structure in MATLAB

This script takes about 1.7 s to run using MATLAB Online (R2019b). … This leads at times to unexpected behavior in MATLAB, where typically b=a, b(1)=0 does not not change a. …
Cris Luengo's user avatar
  • 6,237
2 votes

Simulate transmission spectrum of extreme ultraviolet laser pulse through laser-dressed fini...

Very nice code, it’s hard to find anything to comment on it. 3*10^8 is better written as 3e8 (IEEE float format), then MATLAB doesn’t need to do any computations, though I doubt this would ever be a significant …
Cris Luengo's user avatar
  • 6,237
5 votes

Calculate Mersenne prime numbers in MATLAB

Variable names It's common in MATLAB code to use single-letter variable names. I do this too. Try to use variable names that make the purpose of the variable clear. …
Cris Luengo's user avatar
  • 6,237
4 votes
Accepted

Vector operations

The MATLAB editor can indent for you, simply select the code and press Ctrl+I. Kudos for using ii rather than i! i is a constant in MATLAB, and it's considered bad practice to change its meaning. … You can, for example, read some of the functions that come with MATLAB. …
Cris Luengo's user avatar
  • 6,237
3 votes

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

A named function is declared like this: function out = function_name(in) If it is written in a file of the same name, and the file is on the MATLAB path, then it is accessible from the base workspace …
Cris Luengo's user avatar
  • 6,237
1 vote
Accepted

Applying a function to columns of two matrices producing their combinations

As I've said before, loops are no longer slow in MATLAB, but often it's still possible to remove them ("vectorize the code") for a time gain. … Producing all possible combinations of two values can be accomplished with the bsxfun function in MATLAB. …
Cris Luengo's user avatar
  • 6,237
1 vote

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

I always use the same set(h,'property',value) syntax, because I've been using MATLAB for so long, but do consider the new h.property=value syntax. I find it clearer. … I'm always annoyed at MATLAB using a full page for PDF output, instead of adjusting page size to the figure like it does for all other file formats. …
Cris Luengo's user avatar
  • 6,237
3 votes
Accepted

Array splitting in sub-arrays of consecutive elements

You should preallocate the cs cell array: [v,x] = find(diff(a)>1); %find "jumps" xx = [0 x length(a)]; cs = cell(length(a)+1,1); for ii = 1:length(xx)-1 cs{ii} = a(xx(ii)+1:xx(ii+1)); end Style …
Cris Luengo's user avatar
  • 6,237
2 votes
Accepted

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

When appending to the matrix in this preferred way, MATLAB actually extends the storage of the vector. … MATLAB has a function ismember that does just this: INDX46 = ismember(elec.label, list46); …
Cris Luengo's user avatar
  • 6,237

15 30 50 per page