1 427 total contributions since 2006

Professional Interests: neuroscience, physics, mathematics

Answered

How to change character in multiple cells in to number 0 and 1?

Sex = {'F','M','F','F','M','M','F'} [~, SexNum] = ismember(Sex, {'F','M'}) SexNum = SexNum - 1 % 1 = 'M', 0 = 'F', -1 = other ...

How to change character in multiple cells in to number 0 and 1?

Sex = {'F','M','F','F','M','M','F'} [~, SexNum] = ismember(Sex, {'F','M'}) SexNum = SexNum - 1 % 1 = 'M', 0 = 'F', -1 = other ...

2 jours ago | 0

| accepted

Answered

load files whith a previus specified name

Didn't you just make a simple typo? % Aplha vs Alpha % | |

load files whith a previus specified name

Didn't you just make a simple typo? % Aplha vs Alpha % | |

2 jours ago | 1

| accepted

Answered

Using numpad 8 2 6 4 as North South East West

Perphaps my getkey function may be of use to you: https://www.mathworks.com/matlabcentral/fileexchange/7465-getkey

Using numpad 8 2 6 4 as North South East West

Perphaps my getkey function may be of use to you: https://www.mathworks.com/matlabcentral/fileexchange/7465-getkey

10 jours ago | 0

Answered

I keep getting the error message that vectors must be the same length in the plot command

So, apparently the two vectors are not of the same length. You really should learn how to debug your own code. Set a breakpoint ...

I keep getting the error message that vectors must be the same length in the plot command

So, apparently the two vectors are not of the same length. You really should learn how to debug your own code. Set a breakpoint ...

16 jours ago | 1

Answered

Select random elements from three consecutive columns in a big matrix?

M = magic(5) % input data N = 4 % number of selections nC = 3 % number of consecutive columns % engine szM = size(M) r...

Select random elements from three consecutive columns in a big matrix?

M = magic(5) % input data N = 4 % number of selections nC = 3 % number of consecutive columns % engine szM = size(M) r...

16 jours ago | 0

Answered

select random row inside the cell

You want the row, or the row number to be returned? A={[1,4,6;6,5,4;1,2,4],[1,3;5,4],[1,2;1,7;6,8]} rownumber = cellfun(@(c)...

select random row inside the cell

You want the row, or the row number to be returned? A={[1,4,6;6,5,4;1,2,4],[1,3;5,4],[1,2;1,7;6,8]} rownumber = cellfun(@(c)...

16 jours ago | 0

| accepted

Answered

Vectorizing nested for loops

A = magic(5) d = squareform(pdist(transpose(A))) % transpose to obtain vecnorm between columns pdist and squareform are part ...

Vectorizing nested for loops

A = magic(5) d = squareform(pdist(transpose(A))) % transpose to obtain vecnorm between columns pdist and squareform are part ...

18 jours ago | 1

| accepted

Answered

how to find the element which is greater than or equal to its row and smaller or equal to its column in a matrix

function out = saddle(M) [r, c] = ind2sub(size(M), 1:numel(M)) ; tf = arrayfun(@(r, c) all(M(r, c) >= A(:, c)) && all(M(r, c) ...

how to find the element which is greater than or equal to its row and smaller or equal to its column in a matrix

function out = saddle(M) [r, c] = ind2sub(size(M), 1:numel(M)) ; tf = arrayfun(@(r, c) all(M(r, c) >= A(:, c)) && all(M(r, c) ...

18 jours ago | 0

Answered

omit same element inside cell

You can convert the elements of each cell to a char array and apply unique on that cell array of chars. A = {[1,2,3,4],[4,2,3],...

omit same element inside cell

You can convert the elements of each cell to a char array and apply unique on that cell array of chars. A = {[1,2,3,4],[4,2,3],...

18 jours ago | 1

Answered

How to store vectors into a matrix that have different sizes?

Next to cell arrays, you can also use struct arrays, which can be more ... euh ... structured than cell arrays ;-) a(1).data = ...

How to store vectors into a matrix that have different sizes?

Next to cell arrays, you can also use struct arrays, which can be more ... euh ... structured than cell arrays ;-) a(1).data = ...

18 jours ago | 0

Answered

Repeating or rerunning a loop

Use a while loop, which is more flexible than a for -loop. Something like this might work: seq = [3, 1, 2, 1, 3, 2]; % trial se...

Repeating or rerunning a loop

Use a while loop, which is more flexible than a for -loop. Something like this might work: seq = [3, 1, 2, 1, 3, 2]; % trial se...

20 jours ago | 0

| accepted

Answered

Probability of exactly one even number

I suggest you use two counters: one counting the numbers of even values in a single throw, and one counting the number of throws...

Probability of exactly one even number

I suggest you use two counters: one counting the numbers of even values in a single throw, and one counting the number of throws...

21 jours ago | 1

Answered

How can I get a infinite loop in matlab?

an infinite loop k = 0 ; while true % useful code here k = k + 1 ; disp(k) end But are you sure you want an...

How can I get a infinite loop in matlab?

an infinite loop k = 0 ; while true % useful code here k = k + 1 ; disp(k) end But are you sure you want an...

22 jours ago | 0

Answered

How to use varargin: to specify a second input variable with separate output

You cannot compare strings with different lengths using ==. Use isequal or strcmpi instead, for instance: if isequal(lower(vara...

How to use varargin: to specify a second input variable with separate output

You cannot compare strings with different lengths using ==. Use isequal or strcmpi instead, for instance: if isequal(lower(vara...

23 jours ago | 1

| accepted

Answered

Removing a Range of Elements from an array

ix = find(M(:,12) > 750, 1, 'first') % find the row index of the first element in the 12th column of A being larger than 750 M...

Removing a Range of Elements from an array

ix = find(M(:,12) > 750, 1, 'first') % find the row index of the first element in the 12th column of A being larger than 750 M...

24 jours ago | 0

Answered

How do i average all result in total loop,if some result in some of loop are NaN

Store each result in an array and average after the loop. An example: c = nan(1,10) ; % pre-allocation for speed for k = 1:10 ...

How do i average all result in total loop,if some result in some of loop are NaN

Store each result in an array and average after the loop. An example: c = nan(1,10) ; % pre-allocation for speed for k = 1:10 ...

26 jours ago | 0

| accepted

Answered

Counting occurrences of a pair of numbers in a logical vector

A vectorised alternative: A = [0 1 0 0 1 0 0 0 0 0 1 1 0 0 1 0 1 ]; % Input vector ix = find(A) ix = ix(2:2:end) B = cumsum(...

Counting occurrences of a pair of numbers in a logical vector

A vectorised alternative: A = [0 1 0 0 1 0 0 0 0 0 1 1 0 0 1 0 1 ]; % Input vector ix = find(A) ix = ix(2:2:end) B = cumsum(...

28 jours ago | 0

Answered

Using range in a vector

I am a little confused by your problem, but here are my thoughts. You might want to use the function ANY, or its sibling ALL, or...

Using range in a vector

I am a little confused by your problem, but here are my thoughts. You might want to use the function ANY, or its sibling ALL, or...

environ un mois ago | 0

| accepted

Answered

There is an error in exp function but it doesn't tell what the error is?

Use dbstop if error and inspect the contents of the variables! You'll see what is wrong :-)

There is an error in exp function but it doesn't tell what the error is?

Use dbstop if error and inspect the contents of the variables! You'll see what is wrong :-)

environ un mois ago | 0

Answered

Set up an OR argument for equation

Simpler, without an if-else: v = (xdot_1-xdot_2)).*(sign(x1-x2-gap)+1)/2; fp = (k_inp*(x1-x2-gap) + (v>0) * c_inp * (xdot_1-xd...

Set up an OR argument for equation

Simpler, without an if-else: v = (xdot_1-xdot_2)).*(sign(x1-x2-gap)+1)/2; fp = (k_inp*(x1-x2-gap) + (v>0) * c_inp * (xdot_1-xd...

environ un mois ago | 0

Answered

Set up an OR argument for equation

Can't you use logical indexing? A simplified example v = 10:20 q = v > 13 & v < 18 f(q) = 2*v(q) f(~q) = 30 + v(q)

Set up an OR argument for equation

Can't you use logical indexing? A simplified example v = 10:20 q = v > 13 & v < 18 f(q) = 2*v(q) f(~q) = 30 + v(q)

environ un mois ago | 1

Answered

How can I compare two measurements which are composed of matrices such as [0 1 0 0...]

You are looking for a measure of consistency between two measurements which are represented as binary vectors of the same length...

How can I compare two measurements which are composed of matrices such as [0 1 0 0...]

You are looking for a measure of consistency between two measurements which are represented as binary vectors of the same length...

environ un mois ago | 0

| accepted

Answered

How can I make each cell array consistent in length?

A final attempt to answer this question :-) C = {1:4 1:2 ; 1:5 1:6 ; 1 1:3} % a m-by-n cell array N = cellfun(@numel, C) % old...

How can I make each cell array consistent in length?

A final attempt to answer this question :-) C = {1:4 1:2 ; 1:5 1:6 ; 1 1:3} % a m-by-n cell array N = cellfun(@numel, C) % old...

environ un mois ago | 1

| accepted

Answered

split a diagonal matrix

Having a vector V with any number of elements, this does the job: V = [2 1 4] n = numel(V) ; M = zeros(n,n,n) ; M(linspace...

split a diagonal matrix

Having a vector V with any number of elements, this does the job: V = [2 1 4] n = numel(V) ; M = zeros(n,n,n) ; M(linspace...

environ un mois ago | 1

Answered

Extracting columns from a matrix, corresponding start and end times

The easiest approach is to create a for loop over the events Nevents = nume(EventTimes) R = zeros(64, 250, Nevents) % pre-allo...

Extracting columns from a matrix, corresponding start and end times

The easiest approach is to create a for loop over the events Nevents = nume(EventTimes) R = zeros(64, 250, Nevents) % pre-allo...

environ un mois ago | 0

| accepted

Answered

How can I make each cell array consistent in length?

C = {1:3 4 ; 5:9 10:12 ; 13:14 15} % a m-by-n cell array N = cellfun(@numel, C) maxN = max(N(:)) padfun = @(v) [v zeros(1, m...

How can I make each cell array consistent in length?

C = {1:3 4 ; 5:9 10:12 ; 13:14 15} % a m-by-n cell array N = cellfun(@numel, C) maxN = max(N(:)) padfun = @(v) [v zeros(1, m...

environ un mois ago | 1

Answered

replace values with nans

Take a look at logical indexing or the function ind2sub M = randi(10,8,6) % use indices of elements for which condition is tru...

replace values with nans

Take a look at logical indexing or the function ind2sub M = randi(10,8,6) % use indices of elements for which condition is tru...

environ un mois ago | 0

Answered

Rearranging Array Rows into Multiple Blocks while Maintaining the Old Order

You should learn about indexing, one of the most essential aspects of Matlab: M = randi(4,10,5) ; M(:,1) = 1:size(M,1) % exampl...

Rearranging Array Rows into Multiple Blocks while Maintaining the Old Order

You should learn about indexing, one of the most essential aspects of Matlab: M = randi(4,10,5) ; M(:,1) = 1:size(M,1) % exampl...

environ un mois ago | 1

| accepted

Answered

Combine Array from different cell

This is called concatenation. See the documentation of the function CAT. Matlab allows you to concatenate a bunch of column vec...

Combine Array from different cell

This is called concatenation. See the documentation of the function CAT. Matlab allows you to concatenate a bunch of column vec...

environ un mois ago | 0