1,504 total contributions since 2006

I have been using Matlab since version 4 (1999 or so) and still prefer it over all other software tools available for data manipulation :-)

My professional interests: neuroscience (motor control & eye movements), cognitive psychology physics, mathematics, teaching

"The most important part of programming is writing the comments!"

Answered

making an array to simulate states of a paramagnet with values of -1,+1.

Create a random vector with two values and map those to -1 and 1. An easy solution (with n=10): x = 2 * randi([0 1], 1, 10) - 1...

making an array to simulate states of a paramagnet with values of -1,+1.

Create a random vector with two values and map those to -1 and 1. An easy solution (with n=10): x = 2 * randi([0 1], 1, 10) - 1...

2 days ago | 0

Answered

for loop that changes specific letters to numbers

Another option: str = 'apple'; TF1 = any(lower(str) ~= 'aeiou'.')

for loop that changes specific letters to numbers

Another option: str = 'apple'; TF1 = any(lower(str) ~= 'aeiou'.')

11 days ago | 2

Answered

Finding Min Value in array with changing condition

tf = a == 1 % create a logical array temp = cost(tf) % logical indexing to retrieve certain values mincost = min(t...

Finding Min Value in array with changing condition

tf = a == 1 % create a logical array temp = cost(tf) % logical indexing to retrieve certain values mincost = min(t...

15 days ago | 0

Answered

How to genetate random number under constraint

Brute force attempt: N = 20 ; xyRange = [100 1900] ; minimumDistance = 200 ; attempt_counter = 1 ; Distances = 0 ; while ...

How to genetate random number under constraint

Brute force attempt: N = 20 ; xyRange = [100 1900] ; minimumDistance = 200 ; attempt_counter = 1 ; Distances = 0 ; while ...

18 days ago | 0

Answered

Add an element to a 3D array

To concatenate two arrays A and B in the third dimension, use cat cat(3, A, B) Note that all the other dimensions of A and B s...

Add an element to a 3D array

To concatenate two arrays A and B in the third dimension, use cat cat(3, A, B) Note that all the other dimensions of A and B s...

19 days ago | 0

Answered

To concatenate rows in matrix within for loop based on if else statement

This code is weird. In each iteration of "index" you fill either a matrix temp or a matrix temp_noise with m rows of values. T...

To concatenate rows in matrix within for loop based on if else statement

This code is weird. In each iteration of "index" you fill either a matrix temp or a matrix temp_noise with m rows of values. T...

20 days ago | 1

Answered

To generate matrix from an array

More general, using indexing: A = [1 22 3 44 55 666 7 888 9] n = 2 B = A(((1:numel(A)-n).' + (0:n)))

To generate matrix from an array

More general, using indexing: A = [1 22 3 44 55 666 7 888 9] n = 2 B = A(((1:numel(A)-n).' + (0:n)))

20 days ago | 0

Answered

How to exclude a line in legend?

Get the handles of the lines and create a legend only for the desired handles. It is all in the documentation :-) doc legend

How to exclude a line in legend?

Get the handles of the lines and create a legend only for the desired handles. It is all in the documentation :-) doc legend

20 days ago | 0

| accepted

Answered

Shifting a signal to the right or left

x = 1:5 shift = 3 x = circshift(x,shift) N = numel(x) ix = (1:N) - shift tf = ix < 1 | ix > N x(tf) = 0

Shifting a signal to the right or left

x = 1:5 shift = 3 x = circshift(x,shift) N = numel(x) ix = (1:N) - shift tf = ix < 1 | ix > N x(tf) = 0

24 days ago | 1

Answered

How to make a matrix with the entries being the number of even indices of that entry?

help meshgrid help rem

How to make a matrix with the entries being the number of even indices of that entry?

help meshgrid help rem

1 month ago | 0

Answered

Could anyone help me to solve the issue.

ix = find(abs(diff(A)) < YourThreshold, 1, 'first') % maybe you want to add + 1 B(ix:end) = B(ix)

Could anyone help me to solve the issue.

ix = find(abs(diff(A)) < YourThreshold, 1, 'first') % maybe you want to add + 1 B(ix:end) = B(ix)

1 month ago | 0

Answered

How can I keep the highest N% values of a data set?

Use MAXK: Y = maxk(X, ceil(N * numel(X) / 100))

How can I keep the highest N% values of a data set?

Use MAXK: Y = maxk(X, ceil(N * numel(X) / 100))

1 month ago | 1

| accepted

Answered

Function calculating distance between pixels in 1x1x3 arrays

The function you found is rather badly coded ... Another expression for "calculating a distance" is "taking the norm". Matlab h...

Function calculating distance between pixels in 1x1x3 arrays

The function you found is rather badly coded ... Another expression for "calculating a distance" is "taking the norm". Matlab h...

1 month ago | 1

| accepted

Answered

how to extend the writing of the comments ?

You can set this in the preferences for the editor/debugger. Look for the Right-hand text limit.

how to extend the writing of the comments ?

You can set this in the preferences for the editor/debugger. Look for the Right-hand text limit.

1 month ago | 1

Answered

Best way to calculate the determinants of a series of matrices?

Elaborating on the answers using arrayfun, you can avoid the multiple squeeze operations by permuting the dimension order first:...

Best way to calculate the determinants of a series of matrices?

Elaborating on the answers using arrayfun, you can avoid the multiple squeeze operations by permuting the dimension order first:...

1 month ago | 0

Answered

Fill an array with different size vectors

A=[1,2,3,4]; B=[5,6]; C=[7,8,9]; [ARRAY, tf] = padcat(A,B,C) % pad with NaNs ARRAY(~tf) = 0 % replace those NaNs with zeros ...

Fill an array with different size vectors

A=[1,2,3,4]; B=[5,6]; C=[7,8,9]; [ARRAY, tf] = padcat(A,B,C) % pad with NaNs ARRAY(~tf) = 0 % replace those NaNs with zeros ...

1 month ago | 0

Answered

add new rows to a Matrix

Despite its simple appearance, this is not a trivial task, for which I created my insertrows function A = randperm(10).' B = i...

add new rows to a Matrix

Despite its simple appearance, this is not a trivial task, for which I created my insertrows function A = randperm(10).' B = i...

1 month ago | 0

Answered

reduce rows of a due to b

You can simply use setdiff with the rows option ... c = setdiff(a,b,'rows')

reduce rows of a due to b

You can simply use setdiff with the rows option ... c = setdiff(a,b,'rows')

2 months ago | 0

Answered

exclude values of a matrix inside a for loop

you can replace the outliers by NaN before the loop and then use nanmax and nansum in your calculations

exclude values of a matrix inside a for loop

you can replace the outliers by NaN before the loop and then use nanmax and nansum in your calculations

2 months ago | 0

| accepted

Answered

Find unique or duplicate cells in cell array of chars

A = {{'A', 'B', 'C'}, {'C', 'D', 'E'}, {'A', 'B', 'C'}, {'C', 'B', 'A'}} N = arrayfun(@(k) sum(arrayfun(@(j) isequal(A{k}, A{j}...

Find unique or duplicate cells in cell array of chars

A = {{'A', 'B', 'C'}, {'C', 'D', 'E'}, {'A', 'B', 'C'}, {'C', 'B', 'A'}} N = arrayfun(@(k) sum(arrayfun(@(j) isequal(A{k}, A{j}...

2 months ago | 1

| accepted

Answered

How to compare two vector with different dimension

I assume the elements of x and y are linked? Why is the first element of (x2,y2) than not in the list of coordinaties (x1,y1)? I...

How to compare two vector with different dimension

I assume the elements of x and y are linked? Why is the first element of (x2,y2) than not in the list of coordinaties (x1,y1)? I...

2 months ago | 0

Solved

Back to Basics - Find no. of elements in a matrix?

Let A be a m*n matrix. Find the total no. of elements in A ? (Hint - formula based) A = [1 2 3;4 5 6]; output = 6

2 months ago

Answered

To generate alternate 0's and 1's

bitget(repelem(0:numel(A)-1, A), 1) [update] I modified my original but erroneous answer bitget(repelem(1:numel(A), A), 2). In ...

To generate alternate 0's and 1's

bitget(repelem(0:numel(A)-1, A), 1) [update] I modified my original but erroneous answer bitget(repelem(1:numel(A), A), 2). In ...

2 months ago | 1

Answered

Combine three matrices (every other column)

Or, as a one-liner, using left-hand indexing: % some test data A = cumsum(ones(5,4),2), B = 10 * A, C = 10 * B % left-hand in...

Combine three matrices (every other column)

Or, as a one-liner, using left-hand indexing: % some test data A = cumsum(ones(5,4),2), B = 10 * A, C = 10 * B % left-hand in...

2 months ago | 0

| accepted

Answered

Combine three matrices (every other column)

Assuming matrices A, B and C all have the same N-by-M size: % some test data A = cumsum(ones(5,4),2) ; B = 10 * A ; C = 10 * B...

Combine three matrices (every other column)

Assuming matrices A, B and C all have the same N-by-M size: % some test data A = cumsum(ones(5,4),2) ; B = 10 * A ; C = 10 * B...

2 months ago | 0

Answered

Calculate statistical parameters from certain rows of a matrix

help grpstats help accumarray

Calculate statistical parameters from certain rows of a matrix

help grpstats help accumarray

2 months ago | 0

Answered

How to convert a structure array into vector

Why on earth store scalar values like that? Why not have a simple, highly efficient M-by-N matrix, rather than a cumbersome M-by...

How to convert a structure array into vector

Why on earth store scalar values like that? Why not have a simple, highly efficient M-by-N matrix, rather than a cumbersome M-by...

2 months ago | 0

Answered

For loop within for loop

In recent ML versions there is no need for meshgrid or so. The plus syntax will expand the vectors :-) % a smaller example n =...

For loop within for loop

In recent ML versions there is no need for meshgrid or so. The plus syntax will expand the vectors :-) % a smaller example n =...

2 months ago | 1

Answered

Average of matrix element

One easy option A = [10 20 30 40] B = cumsum(A) ./ (1:numel(A))

Average of matrix element

One easy option A = [10 20 30 40] B = cumsum(A) ./ (1:numel(A))

2 months ago | 0