1 495 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

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

6 dagar 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)

6 dagar 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))

6 dagar ago | 1

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

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

13 dagar 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:...

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

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

19 dagar 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')

20 dagar 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

21 dagar 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}...

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

21 dagar 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

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

ungefär en månad 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...

ungefär en månad 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...

ungefär en månad 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

ungefär en månad 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...

ungefär en månad 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 =...

ungefär en månad 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))

ungefär en månad 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...

ungefär en månad 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})

ungefär en månad 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...

ungefär en månad 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...

ungefär en månad 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...

ungefär 2 månader 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...

ungefär 2 månader 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 ...

ungefär 2 månader 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...

3 månader 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...

3 månader ago | 0