Data scientist at Cohen Veterans Bioscience; Obsessive runner. Professional Interests: Predictive modeling, statistics. (I don't respond to email via author page, but will usually look at a question if you send me a link to it.)

Answered

Issues converting a Cell to a numerical array

Here is one way that may work for you: C = {1, 3, 7, 7, 'a'}; N = cell2mat(C(cellfun(@isnumeric,C)))

Issues converting a Cell to a numerical array

Here is one way that may work for you: C = {1, 3, 7, 7, 'a'}; N = cell2mat(C(cellfun(@isnumeric,C)))

1 day ago | 0

Answered

3D Matrix Multiplication

You can do it straightforwardly with a for loop: % Some made-up input data A = rand(3,1,4); B = rand(3,3,4); [mA,nA,pA] = ...

3D Matrix Multiplication

You can do it straightforwardly with a for loop: % Some made-up input data A = rand(3,1,4); B = rand(3,3,4); [mA,nA,pA] = ...

1 day ago | 0

| accepted

Answered

fitlm() with 0 intercept function returns different values for R2 betwen MATLAB 2020a and 2020b?

Interesting. The 2020b result seems to be correct, based on the formula using sums of squares. (See, e.g. the definition on wiki...

fitlm() with 0 intercept function returns different values for R2 betwen MATLAB 2020a and 2020b?

Interesting. The 2020b result seems to be correct, based on the formula using sums of squares. (See, e.g. the definition on wiki...

2 days ago | 1

Answered

Creating a Histogram of Letter grades converted from number grades

I'm sorry to say that the approach in your code is so misguided, that it is probably not worth debugging it. You need a differen...

Creating a Histogram of Letter grades converted from number grades

I'm sorry to say that the approach in your code is so misguided, that it is probably not worth debugging it. You need a differen...

3 days ago | 0

Answered

how to get random pair ?

How are these pairs currently stored? This seems equivalent to just choosing a random number from 1-6, so you could do idx = r...

how to get random pair ?

How are these pairs currently stored? This seems equivalent to just choosing a random number from 1-6, so you could do idx = r...

3 days ago | 0

Answered

How to plot function with variable input like shown in figure?

I didn't fully understand what you are trying to do, but the fplot command might be useful.

How to plot function with variable input like shown in figure?

I didn't fully understand what you are trying to do, but the fplot command might be useful.

4 days ago | 0

Answered

Producing a NaN only where there is a NaN, zero otherwise

Second attempt ... X = [-inf, -1, -eps, 0, realmin, 2, 1+i, pi, flintmax, realmax, inf, NaN]; broken = @(x) 0./(isnan(x)-1); %...

Producing a NaN only where there is a NaN, zero otherwise

Second attempt ... X = [-inf, -1, -eps, 0, realmin, 2, 1+i, pi, flintmax, realmax, inf, NaN]; broken = @(x) 0./(isnan(x)-1); %...

4 days ago | 1

Answered

Producing a NaN only where there is a NaN, zero otherwise

First attempt: X = [-inf, -1, -eps, 0, realmin, 2, 1+i, pi, flintmax, realmax, inf, NaN]; broken = @(x) 1./((isnan(x)-1)/0); %...

Producing a NaN only where there is a NaN, zero otherwise

First attempt: X = [-inf, -1, -eps, 0, realmin, 2, 1+i, pi, flintmax, realmax, inf, NaN]; broken = @(x) 1./((isnan(x)-1)/0); %...

4 days ago | 1

Answered

How do I remove NaN's from my data?

If your numeric vector is called "x", then x(isnan(x)) = []; will remove the NaN values.

How do I remove NaN's from my data?

If your numeric vector is called "x", then x(isnan(x)) = []; will remove the NaN values.

5 days ago | 0

Answered

Plot of 4D coordinates

You may be able to find something you can adapt at the MATLAB Plot Gallery.

Plot of 4D coordinates

You may be able to find something you can adapt at the MATLAB Plot Gallery.

5 days ago | 0

Answered

How to get the first value in a set of array that is bigger than the first few values?

Because x and y are not the same length, I'm not sure how to make the "correspondence" between them. However, this code snippet ...

How to get the first value in a set of array that is bigger than the first few values?

Because x and y are not the same length, I'm not sure how to make the "correspondence" between them. However, this code snippet ...

5 days ago | 1

Answered

Using if condition store values in an array

If I understand you correctly, this does what you want. (It doesn't directly use "if", but does the job via logical indexing ins...

Using if condition store values in an array

If I understand you correctly, this does what you want. (It doesn't directly use "if", but does the job via logical indexing ins...

7 days ago | 0

| accepted

Answered

Sort an Array with sortrows ( ) with two columns

See my answer (and other comments) to this very similar question. (As with the comments above, the premise is that the displayed...

Sort an Array with sortrows ( ) with two columns

See my answer (and other comments) to this very similar question. (As with the comments above, the premise is that the displayed...

7 days ago | 1

Answered

How to make slope 1in fitlm?

I don't believe you can do it with fitlm, but you can with fitnlm: % Set seed for reproducibility rng default % Make up som...

How to make slope 1in fitlm?

I don't believe you can do it with fitlm, but you can with fitnlm: % Set seed for reproducibility rng default % Make up som...

7 days ago | 0

| accepted

Answered

Multiplying a Matrix with every column of another matrix

Do you mean you just want to do standard matrix multipication? C = A * B Or did I misunderstand?

Multiplying a Matrix with every column of another matrix

Do you mean you just want to do standard matrix multipication? C = A * B Or did I misunderstand?

8 days ago | 1

| accepted

Answered

How to remove this error?

We can't really answer that for you, because we need more information. Suppose x = [1 2 3 4]; y = [5 6 2 3]; If I want to pl...

How to remove this error?

We can't really answer that for you, because we need more information. Suppose x = [1 2 3 4]; y = [5 6 2 3]; If I want to pl...

8 days ago | 0

Answered

What is prodofsize?

It is mentioned in the "Backward Compatibility" section of the documentation of cellfun, although there doesn't seem to be any i...

What is prodofsize?

It is mentioned in the "Backward Compatibility" section of the documentation of cellfun, although there doesn't seem to be any i...

8 days ago | 0

| accepted

Answered

Array indices must be positive integers or logical values error

You need X = (2*r2*((cosd(0)*cosd(theta2)))); instead of X = (2*r2((cosd(0)*cosd(theta2)))); (Note that I used r2* instead o...

Array indices must be positive integers or logical values error

You need X = (2*r2*((cosd(0)*cosd(theta2)))); instead of X = (2*r2((cosd(0)*cosd(theta2)))); (Note that I used r2* instead o...

9 days ago | 0

Answered

How to insert multiple element after specific numbers in a vector?

Here is one way % Original logical vector input L = logical([1 0 1 1 0]); % The numbers to be inserted oneNum = 6; zeroNu...

How to insert multiple element after specific numbers in a vector?

Here is one way % Original logical vector input L = logical([1 0 1 1 0]); % The numbers to be inserted oneNum = 6; zeroNu...

12 days ago | 0

Answered

Addition in 3D matrix

% Define some pretend data, the size of your original matrix M = rand(62,50,341); % Intervals interval = [8,30,31,31,30,31,...

Addition in 3D matrix

% Define some pretend data, the size of your original matrix M = rand(62,50,341); % Intervals interval = [8,30,31,31,30,31,...

12 days ago | 0

Answered

Shifting columns in matrix Matlab

Slightly simpler version of @Nora Khaled's idea. It will also generalize to an (N-1) X N array in a way that I believe makes sen...

Shifting columns in matrix Matlab

Slightly simpler version of @Nora Khaled's idea. It will also generalize to an (N-1) X N array in a way that I believe makes sen...

14 days ago | 0

| accepted

Answered

Fitting the data to power law using least square method

Here is code that will do the fit in the original space, without applying the log transform first: % Load the data data = read...

Fitting the data to power law using least square method

Here is code that will do the fit in the original space, without applying the log transform first: % Load the data data = read...

14 days ago | 0

| accepted

Answered

Why is xcorr getting this very simple case "wrong"?

I didn't figure this out with certainty, but if you take a look at the "More About" section of the documentation for xcorr, it m...

Why is xcorr getting this very simple case "wrong"?

I didn't figure this out with certainty, but if you take a look at the "More About" section of the documentation for xcorr, it m...

14 days ago | 0

Answered

Fitting the data to power law using least square method

I would solve this by first applying a natural log transform to both sides of the equation, which then gives you a linear equati...

Fitting the data to power law using least square method

I would solve this by first applying a natural log transform to both sides of the equation, which then gives you a linear equati...

15 days ago | 0

Answered

Error - Index in position 1 exceeds array bounds (must not exceed 10)

I think you want for row = 3:size(x1,1)-1 end instead of for row = 3:size(x1,1) end so that you don't try to acc...

Error - Index in position 1 exceeds array bounds (must not exceed 10)

I think you want for row = 3:size(x1,1)-1 end instead of for row = 3:size(x1,1) end so that you don't try to acc...

16 days ago | 0

| accepted

Answered

Convert cell array to matrix with two columns and sort rows by first column value

I think this does what you want: % Set RNG seed, for repeatability rng default % Make up some data Cell_x = {rand(13,2),ra...

Convert cell array to matrix with two columns and sort rows by first column value

I think this does what you want: % Set RNG seed, for repeatability rng default % Make up some data Cell_x = {rand(13,2),ra...

16 days ago | 0

Answered

How to obtain an array of constant values from vector valued anonymous functions

f=@(x) 3.5 * ones(size(x)); v=0:10; y=f(v)

How to obtain an array of constant values from vector valued anonymous functions

f=@(x) 3.5 * ones(size(x)); v=0:10; y=f(v)

16 days ago | 1

| accepted

Answered

why I'm getting error " Array indices must be positive integers or logical values."

You need the multiplication sign after Patm: func_atm_pressure=@(Z) P-Patm*(1+((B*Z)/Tatm))^(g/(R*B));

why I'm getting error " Array indices must be positive integers or logical values."

You need the multiplication sign after Patm: func_atm_pressure=@(Z) P-Patm*(1+((B*Z)/Tatm))^(g/(R*B));

16 days ago | 0

Answered

Calculate the area between two curves

Because your curves are smooth, I think using interpolated curves will be useful: xx = 0 : 0.01 : min(max(x1),max(x2)); yy1 = ...

Calculate the area between two curves

Because your curves are smooth, I think using interpolated curves will be useful: xx = 0 : 0.01 : min(max(x1),max(x2)); yy1 = ...

17 days ago | 0

Answered

Create array with integral values

% original vector v = rand(1,3366); r = reshape(v,66,[]); % You may need to do a step where you remove the last row of r,...

Create array with integral values

% original vector v = rand(1,3366); r = reshape(v,66,[]); % You may need to do a step where you remove the last row of r,...

17 days ago | 0

| accepted