1,455 total contributions since 2006

Professional Interests: neuroscience, physics, mathematics

Answered

Transform NaN into number

This function recursively looks at all fields of the structure and replaces any NaNs by a value. Also works for structure arrays...

Transform NaN into number

This function recursively looks at all fields of the structure and replaces any NaNs by a value. Also works for structure arrays...

22 hours ago | 1

Submitted

RANDPERMFULL

RANDPERMFULL (N) returns a random derangement (complete permutation) of the integers from 1 to N

23 hours ago | 3 downloads |

Answered

cell2mat conversion

Do you want to convert the 1-by-28 cell array C, each cell holding a 10-by-25 double matrix to a 3D double array M of size 10-by...

cell2mat conversion

Do you want to convert the 1-by-28 cell array C, each cell holding a 10-by-25 double matrix to a 3D double array M of size 10-by...

2 days ago | 0

Answered

Follow up: How can I merge two different tables using the first column in common?

% data, (showing the drawback of storing relates things in different variables) A = [1 7; 3 15] B = [2 9; 5 10] ...

Follow up: How can I merge two different tables using the first column in common?

% data, (showing the drawback of storing relates things in different variables) A = [1 7; 3 15] B = [2 9; 5 10] ...

3 days ago | 0

| accepted

Answered

Any small program that is also really cool?

Take a look at the function why.m >> type why

Any small program that is also really cool?

Take a look at the function why.m >> type why

3 days ago | 0

| accepted

Answered

Error in the for loop or equality sign

Welcome to the world of floating point arithmetic, where if 0.1+0.2 == 0.3 disp('0.1+0.2 equals 0.3') else disp('0.1...

Error in the for loop or equality sign

Welcome to the world of floating point arithmetic, where if 0.1+0.2 == 0.3 disp('0.1+0.2 equals 0.3') else disp('0.1...

3 days ago | 1

Answered

is there any way to replace this code part with an equivalent part that runs faster?

help cumsum

is there any way to replace this code part with an equivalent part that runs faster?

help cumsum

3 days ago | 0

Answered

Combination of X and Y vectors to get all possible positions on a Cartesian plane

For two vectors, x and y, this might be faster than ndgrid (not tested) xy = [repelem(x(:), numel(y), 1) repmat(y(:), numel(x),...

Combination of X and Y vectors to get all possible positions on a Cartesian plane

For two vectors, x and y, this might be faster than ndgrid (not tested) xy = [repelem(x(:), numel(y), 1) repmat(y(:), numel(x),...

3 days ago | 0

Answered

Adding Zeroes and Ones into a Vector

Inserting elements at specific locations is not trivial. Years ago I wrote a function INSERTROWS that does this https://uk.math...

Adding Zeroes and Ones into a Vector

Inserting elements at specific locations is not trivial. Years ago I wrote a function INSERTROWS that does this https://uk.math...

3 days ago | 1

Answered

constructing symatrical matrix out of vector

v = [1, 2*6, 2*7, 2*8, 2*9, 2, 2*10, 2*11 2*12, 3, 2*13, 2*14, 4, 2*15, 5] % | % I ass...

constructing symatrical matrix out of vector

v = [1, 2*6, 2*7, 2*8, 2*9, 2, 2*10, 2*11 2*12, 3, 2*13, 2*14, 4, 2*15, 5] % | % I ass...

3 days ago | 0

| accepted

Answered

How to find first '1' in every row

Not better than using max (for this type of input), but just to show you an alternative: A = [ 0 0 0 0 0 0 1 1 1 1 0 0; 0 0 0 ...

How to find first '1' in every row

Not better than using max (for this type of input), but just to show you an alternative: A = [ 0 0 0 0 0 0 1 1 1 1 0 0; 0 0 0 ...

4 days ago | 1

Answered

How writing code sum 1+2+3+4+...+n

or know your math classics ... n = 120345428372 s = n*(n+1)/2 % sum(1:n) will fail!

How writing code sum 1+2+3+4+...+n

or know your math classics ... n = 120345428372 s = n*(n+1)/2 % sum(1:n) will fail!

7 days ago | 0

Answered

How to output random number each time a for loop repeats?

You can use an extra variable to keep track of the letters that were guessed correctly. InputString = 'hello' N = numel(InputS...

How to output random number each time a for loop repeats?

You can use an extra variable to keep track of the letters that were guessed correctly. InputString = 'hello' N = numel(InputS...

8 days ago | 0

| accepted

Answered

a question on for loop statement

This is filtering. T=10; % smaller example k=0.1; u=rand(T,1); % your loop -> a a = zeros(T,1); a(1) =u(1)+ k*0.01; ...

a question on for loop statement

This is filtering. T=10; % smaller example k=0.1; u=rand(T,1); % your loop -> a a = zeros(T,1); a(1) =u(1)+ k*0.01; ...

8 days ago | 3

Answered

Select random data from a matrix and replace it

Here is another, indexing, approach: A = randi(2, 6, 8)-1 % random 0/1 array M = 3 % max number of 1's per column szA = s...

Select random data from a matrix and replace it

Here is another, indexing, approach: A = randi(2, 6, 8)-1 % random 0/1 array M = 3 % max number of 1's per column szA = s...

9 days ago | 1

Answered

Create a Cell Array of Vectors populated with ones

repmat also works for cell arrays C = repmat({nan(1, 200)}, 10, 3)

Create a Cell Array of Vectors populated with ones

repmat also works for cell arrays C = repmat({nan(1, 200)}, 10, 3)

9 days ago | 1

| accepted

Answered

filling a matrix with a loop

% clever indexing trick A= [1 1 0 1] N = 10 ; % smaller example! 400 in your case X = triu(toeplitz(1:N)) ; X(X > numel(A)) ...

filling a matrix with a loop

% clever indexing trick A= [1 1 0 1] N = 10 ; % smaller example! 400 in your case X = triu(toeplitz(1:N)) ; X(X > numel(A)) ...

10 days ago | 0

Submitted

PERMPOS

all possible ordered permutations of M values in N positions

10 days ago | 5 downloads |

Answered

Concatenate Structures: select structures only if not empty.

This clearly shows the drawback of naming your variables dynamically, like A1, A2, A3, A4. If you change, for instance, the way ...

Concatenate Structures: select structures only if not empty.

This clearly shows the drawback of naming your variables dynamically, like A1, A2, A3, A4. If you change, for instance, the way ...

20 days ago | 1

| accepted

Answered

How to find slope of this line

You can create a complete list of x,y pairs by expanding x to the size of y. Looking at your code, I think a single element of x...

How to find slope of this line

You can create a complete list of x,y pairs by expanding x to the size of y. Looking at your code, I think a single element of x...

21 days ago | 0

| accepted

Answered

Dissect a String and create list with Matlab

A = "black || white || pink || yellow" B = split(erase(A,'|')).'

Dissect a String and create list with Matlab

A = "black || white || pink || yellow" B = split(erase(A,'|')).'

22 days ago | 0

| accepted

Answered

Removing NaNs from a struct

TF = arrayfun(@(k) isnan(AllData.Passive(k).T(1)), 1:numel(AllData.Passive)) AllData.Passive(TF) = []

Removing NaNs from a struct

TF = arrayfun(@(k) isnan(AllData.Passive(k).T(1)), 1:numel(AllData.Passive)) AllData.Passive(TF) = []

23 days ago | 1

Answered

Changing Indexing Order in matrix raws

Your question is a little confusing, but here is my take on it: A1 = [0 0 0 0 0 0 0 0 0 1 2 3 4 5] A2 = [12 11 14 5 1] out([n...

Changing Indexing Order in matrix raws

Your question is a little confusing, but here is my take on it: A1 = [0 0 0 0 0 0 0 0 0 1 2 3 4 5] A2 = [12 11 14 5 1] out([n...

23 days ago | 1

Answered

Repeating a function n times with different values from a vector

If you organize the input differently, this is not so difficult x = [1 2 ; 3 4 ; 5 6] ; % organized into rows N = size(x,1) ; ...

Repeating a function n times with different values from a vector

If you organize the input differently, this is not so difficult x = [1 2 ; 3 4 ; 5 6] ; % organized into rows N = size(x,1) ; ...

23 days ago | 1

| accepted

Answered

i have a question that works backwards

What about % X is known F = X D = ones(size(F)) % F ./ (D.^5) equals X or is this to simply thought by me ;-)

i have a question that works backwards

What about % X is known F = X D = ones(size(F)) % F ./ (D.^5) equals X or is this to simply thought by me ;-)

25 days ago | 0

Answered

How can i use nchoosek to output both the k combinations and the remaining combinations?

The remaining values can simply be obtained using nchoosek(1:n, n-k), you just have to flip the order of the output :-) n = 7 ...

How can i use nchoosek to output both the k combinations and the remaining combinations?

The remaining values can simply be obtained using nchoosek(1:n, n-k), you just have to flip the order of the output :-) n = 7 ...

26 days ago | 2

Answered

How to create a matrix from for loop result?

D = [170, -80, -30, 0, -50, -30, 20, -60, 100, -60 -20]; Iplus=find(D>0); A = [] ; % initialize for i=1:size(Iplus,...

How to create a matrix from for loop result?

D = [170, -80, -30, 0, -50, -30, 20, -60, 100, -60 -20]; Iplus=find(D>0); A = [] ; % initialize for i=1:size(Iplus,...

26 days ago | 0

| accepted

Answered

How to select desired row

ix = [0:224:81563]' + 1:112 ; % calculate row indices ix(ix>size(A,1)) = [] % remove row indices that are too larger A2 = A(ix...

How to select desired row

ix = [0:224:81563]' + 1:112 ; % calculate row indices ix(ix>size(A,1)) = [] % remove row indices that are too larger A2 = A(ix...

29 days ago | 1

| accepted