1,481 total contributions since 2006

Professional Interests: neuroscience, physics, mathematics

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

9 days 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...

12 days 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...

12 days 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

13 days 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...

16 days 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 =...

16 days 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))

17 days ago | 0

Answered

Extracting and sorting data in a column

This works for both an even or an odd number of elements: N = 11 ; % odd Mx = randi(10, N, 1) M2 = accumarray(ceil((1:numel(M...

Extracting and sorting data in a column

This works for both an even or an odd number of elements: N = 11 ; % odd Mx = randi(10, N, 1) M2 = accumarray(ceil((1:numel(M...

17 days ago | 0

Answered

inefficient loop to vertically concatenate tables

You can apply comma-separated list expansion to tables too, so this one-liner should work. tableBig = cat(1, output{:,2})

inefficient loop to vertically concatenate tables

You can apply comma-separated list expansion to tables too, so this one-liner should work. tableBig = cat(1, output{:,2})

17 days ago | 1

| accepted

Answered

Why is the mean of value of gaussian white noise not zero?

The numbers are randomly drawn from a normal distribution. Although this underlyin distribution has a mean of 0 and a standard d...

Why is the mean of value of gaussian white noise not zero?

The numbers are randomly drawn from a normal distribution. Although this underlyin distribution has a mean of 0 and a standard d...

17 days ago | 0

| accepted

Answered

How to segment an array to different parts?

First of all, do not create separate variabeles for things that are related. A solution using cell arrays (like Kalyan does in h...

How to segment an array to different parts?

First of all, do not create separate variabeles for things that are related. A solution using cell arrays (like Kalyan does in h...

19 days ago | 0

Answered

convert an array into its counting sequence..

This is called run-length encoding, for which there are very efficient functions available on the File Exchange. https://uk.mat...

convert an array into its counting sequence..

This is called run-length encoding, for which there are very efficient functions available on the File Exchange. https://uk.mat...

23 days ago | 0

Answered

How can I store a matrix of varying size in each iteration of a for loop?

Since T and Y are related for a specific value of rho, a struct array is useful here. rho_range = 500:100:1000 ; for k = 1:num...

How can I store a matrix of varying size in each iteration of a for loop?

Since T and Y are related for a specific value of rho, a struct array is useful here. rho_range = 500:100:1000 ; for k = 1:num...

23 days ago | 0

| accepted

Answered

Calculate mean values of specific (but dynamic) intervals

% interval and value are the relevant columns of your data matrix interval = data(:,3) value = data(:,2) % find the sections ...

Calculate mean values of specific (but dynamic) intervals

% interval and value are the relevant columns of your data matrix interval = data(:,3) value = data(:,2) % find the sections ...

24 days ago | 0

| accepted

Answered

Counting the Same Occurance of a row string

A solution with less calls to unique: P = {'ADS','µSOIC8';'AVX','0603';'AVX','0603';'AVX','0603';'ELN','';'EPC','0603';'EPC','0...

Counting the Same Occurance of a row string

A solution with less calls to unique: P = {'ADS','µSOIC8';'AVX','0603';'AVX','0603';'AVX','0603';'ELN','';'EPC','0603';'EPC','0...

2 months ago | 0

Answered

Randomly select an element from a vector satisfying a condition

This is a two-step process: create an intermediate array with all elements of X satisfying your condition select a single elem...

Randomly select an element from a vector satisfying a condition

This is a two-step process: create an intermediate array with all elements of X satisfying your condition select a single elem...

2 months ago | 0

Answered

Count the adjacent same elements in a vector

This is call run-length encoding, for which you can find excellent function on the File exchange. For instance, [shameless self ...

Count the adjacent same elements in a vector

This is call run-length encoding, for which you can find excellent function on the File exchange. For instance, [shameless self ...

2 months ago | 1

Answered

I am supposed to get list of matrices but I am getting this.What do they mean?

Your variable is a cell array, which is a very useful and common way to store things in matlab. Read more on cell arrays in the ...

I am supposed to get list of matrices but I am getting this.What do they mean?

Your variable is a cell array, which is a very useful and common way to store things in matlab. Read more on cell arrays in the ...

2 months ago | 1

Answered

Storing Matrices from a for loop

One option is to use an index to loop over the values, like this. You can than directly use that index to create a cell array to...

Storing Matrices from a for loop

One option is to use an index to loop over the values, like this. You can than directly use that index to create a cell array to...

3 months ago | 1

| accepted

Answered

Using the switch statement inside the for loop.

I suggest you try to avoid a switch statement inside the for-loop as this will probably slow down things a lot. Depending on wha...

Using the switch statement inside the for loop.

I suggest you try to avoid a switch statement inside the for-loop as this will probably slow down things a lot. Depending on wha...

3 months ago | 0

Answered

2-x axes and 1-y axis

What about 'abusing' plotyy? x = 0:0.01:20; y1 = 200*exp(-0.05*x).*sin(x); y2 = 0.8*exp(-0.5*x).*sin(10*x); plotyy(x, y1, x,...

2-x axes and 1-y axis

What about 'abusing' plotyy? x = 0:0.01:20; y1 = 200*exp(-0.05*x).*sin(x); y2 = 0.8*exp(-0.5*x).*sin(10*x); plotyy(x, y1, x,...

3 months ago | 0

Answered

Plotting a series for n>=1

I suggest you avoid meshgrid here. Another tip is to rewrite your function to a somewat simpler form, so you do not loose track ...

Plotting a series for n>=1

I suggest you avoid meshgrid here. Another tip is to rewrite your function to a somewat simpler form, so you do not loose track ...

3 months ago | 0

Answered

Find out if X out of Y elements of an array are true

Let TF be your logical array and X the index of the last updated element then ConditionIsMet = TF(x) && sum(TF) == 4 will be t...

Find out if X out of Y elements of an array are true

Let TF be your logical array and X the index of the last updated element then ConditionIsMet = TF(x) && sum(TF) == 4 will be t...

3 months ago | 0

| accepted

Answered

matrix with mixed data ?

A table is the most obvious choice for this, especially if you want to do statistics. I suggest you read the manual on tables.

matrix with mixed data ?

A table is the most obvious choice for this, especially if you want to do statistics. I suggest you read the manual on tables.

3 months ago | 0

| accepted

Answered

requirement Switch & Case expression with matrix

I suggest you use ISMEMBER with the rows option, rather than if-else (or switch) fieldlist = [x3 y3 ; x1 y1 ; x2 y2] ; filed...

requirement Switch & Case expression with matrix

I suggest you use ISMEMBER with the rows option, rather than if-else (or switch) fieldlist = [x3 y3 ; x1 y1 ; x2 y2] ; filed...

3 months ago | 0

Answered

analyze Consecutive points in an array

Let x be your vector. MyFun = @(i) x(i)>=0.2 && x(i+1)>=0.2 && x(i+2)>=0.2 && x(i-1)<0.2 && x(i-2)<0.2 % MyFun(k) will return ...

analyze Consecutive points in an array

Let x be your vector. MyFun = @(i) x(i)>=0.2 && x(i+1)>=0.2 && x(i+2)>=0.2 && x(i-1)<0.2 && x(i-2)<0.2 % MyFun(k) will return ...

3 months ago | 1

| accepted

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

3 months ago | 1

Submitted

RANDPERMFULL

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

3 months ago | 0 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...

3 months 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 months ago | 0

| accepted