4,012 total contributions since 2011

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

Setting array indices to a vector of values

You can use sub2ind command to convert the subscripted indices (xVal,yVal) into a single linear index into the array.

Setting array indices to a vector of values

You can use sub2ind command to convert the subscripted indices (xVal,yVal) into a single linear index into the array.

1 day ago | 0

Answered

CAN I use matlab in two different computers

Yes, you can use it on up to four computers, according to this page. (Click on "Learn More".) You just need to download and act...

CAN I use matlab in two different computers

Yes, you can use it on up to four computers, according to this page. (Click on "Learn More".) You just need to download and act...

2 days ago | 0

| accepted

Answered

Subscript indices must either be real positive integers or logicals.

In this line: np = find(kp > 1.05 & kp <1.2); there are no values of kp that satisfy this condition, so np is empty. That car...

Subscript indices must either be real positive integers or logicals.

In this line: np = find(kp > 1.05 & kp <1.2); there are no values of kp that satisfy this condition, so np is empty. That car...

5 days ago | 0

| accepted

Answered

Multiplying a string with 1 or 0

Here is one way: c = ['A', repmat('+B',Check_B)]; Be aware that you are actually working with character arrays, not strings.

Multiplying a string with 1 or 0

Here is one way: c = ['A', repmat('+B',Check_B)]; Be aware that you are actually working with character arrays, not strings.

5 days ago | 0

| accepted

Answered

inserting vectors into another new vector

Here is another way: A = [7 17 27 35]; B = [13 22 30 31]; C = [A; [B nan(numel(A)-numel(B),1)]]; C = C(1:(numel(A)+numel(B...

inserting vectors into another new vector

Here is another way: A = [7 17 27 35]; B = [13 22 30 31]; C = [A; [B nan(numel(A)-numel(B),1)]]; C = C(1:(numel(A)+numel(B...

8 days ago | 1

Answered

I keep getting the error "Array indices must be positive integers or logical values?"

In expressions like this one k2(x2(n,:)-x1(n,:)) MATLAB is trying to index into the variable k2. You need to put in the multip...

I keep getting the error "Array indices must be positive integers or logical values?"

In expressions like this one k2(x2(n,:)-x1(n,:)) MATLAB is trying to index into the variable k2. You need to put in the multip...

9 days ago | 1

| accepted

Answered

Making the Y-axis a scale of a specific variable

Here is one way: r = 7; m = 50; N = 50; x = rand(N,1); y = m*rand(N,1); figure plot(x,y,'.'); set(gca,'YTick',0:r:ma...

Making the Y-axis a scale of a specific variable

Here is one way: r = 7; m = 50; N = 50; x = rand(N,1); y = m*rand(N,1); figure plot(x,y,'.'); set(gca,'YTick',0:r:ma...

9 days ago | 0

| accepted

Answered

how to estimate the distribution of a random variable knowing the histogram?

Do you have the underlying data, or only the counts from each bin? Were you hoping to find a particular functional form (e.g. a...

how to estimate the distribution of a random variable knowing the histogram?

Do you have the underlying data, or only the counts from each bin? Were you hoping to find a particular functional form (e.g. a...

9 days ago | 0

Answered

Index exceeds the number of array elements (0)

Everywhere that you wrote zeros(i:1) I think you meant zeros(i,1)

Index exceeds the number of array elements (0)

Everywhere that you wrote zeros(i:1) I think you meant zeros(i,1)

9 days ago | 0

Answered

Curve Fit data using FIT

I used nlinfit from the Statistics and Machine Learning Toolbox. Here is the code, and the resulting plot: xy = [ ... 1 317.3...

Curve Fit data using FIT

I used nlinfit from the Statistics and Machine Learning Toolbox. Here is the code, and the resulting plot: xy = [ ... 1 317.3...

9 days ago | 0

Answered

Extracting certain values from a cell array with nth columns containing double arrays

mC = cellfun(@(x)max(x(:,3)),C)

Extracting certain values from a cell array with nth columns containing double arrays

mC = cellfun(@(x)max(x(:,3)),C)

10 days ago | 0

| accepted

Answered

Finding length between two array elements.

The RunLength utility from the File Exchange might be handy. Run it in a loop over each column.

Finding length between two array elements.

The RunLength utility from the File Exchange might be handy. Run it in a loop over each column.

11 days ago | 0

Answered

Draw vertical lines on a plot

If you have R2018b or later, you can use the xline command. If you have an earlier version, you can use the line command (which...

Draw vertical lines on a plot

If you have R2018b or later, you can use the xline command. If you have an earlier version, you can use the line command (which...

11 days ago | 0

Answered

Beginner's question about data plot

Try this instead plot(time,Enable_d,'.','MarkerSize',32) This code will plot individual points, without a connecting line.

Beginner's question about data plot

Try this instead plot(time,Enable_d,'.','MarkerSize',32) This code will plot individual points, without a connecting line.

11 days ago | 0

Answered

How can vectorize the below codes?

Well, not vectorizing it, but if you preallocate etas and phis with these line: etas = zeros(262144,2); phis = zeros(262144,2)...

How can vectorize the below codes?

Well, not vectorizing it, but if you preallocate etas and phis with these line: etas = zeros(262144,2); phis = zeros(262144,2)...

12 days ago | 0

| accepted

Answered

Dear friends, the long matlab command that I have written is error. I want to be spelled the same way but without error.

Do it like the second example on this documentation page about continuing long statements on multiple lines.

Dear friends, the long matlab command that I have written is error. I want to be spelled the same way but without error.

Do it like the second example on this documentation page about continuing long statements on multiple lines.

14 days ago | 1

| accepted

Answered

Simple if statement also executes if condition not met - What am I doing wrong?

I ran the following code: dist_psd = [1 1 1 1 NaN]; time_psd = [1 1 1 NaN NaN]; for i = 1:length(dist_psd); if (isna...

Simple if statement also executes if condition not met - What am I doing wrong?

I ran the following code: dist_psd = [1 1 1 1 NaN]; time_psd = [1 1 1 NaN NaN]; for i = 1:length(dist_psd); if (isna...

16 days ago | 0

| accepted

Answered

update vector with nubers from another vector

A = [ 2 4 6 10 15]; B = [2.43 2.3 12 5.1]; [~,idx] = min(abs(B'-A),[],2); B = A(idx)

update vector with nubers from another vector

A = [ 2 4 6 10 15]; B = [2.43 2.3 12 5.1]; [~,idx] = min(abs(B'-A),[],2); B = A(idx)

16 days ago | 1

| accepted

Answered

Sorting numbers in an array without sort function

if all(diff(X)) >= 0 Also, rather than defining the finished variable, you could have just made that the condition for the whil...

Sorting numbers in an array without sort function

if all(diff(X)) >= 0 Also, rather than defining the finished variable, you could have just made that the condition for the whil...

17 days ago | 0

Answered

i want to know whats is the problem in this code during running

Are you trying to just paste that code into the command line, and running it? Instead, you should save that function code into ...

i want to know whats is the problem in this code during running

Are you trying to just paste that code into the command line, and running it? Instead, you should save that function code into ...

17 days ago | 0

Answered

how to remove zeros from the matrix?

I think this does what you want: % Replicate A into B B = A; % For the even-numbered rows, circularly shift the elements B...

how to remove zeros from the matrix?

I think this does what you want: % Replicate A into B B = A; % For the even-numbered rows, circularly shift the elements B...

19 days ago | 1

| accepted

Answered

Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 2-by-2.

In the line of code giving the error: A(i,j)=(0.5)*(c)*(Cla).*(C(i,j))+k(i,j) you are using the full matrix c. Maybe you wante...

Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 2-by-2.

In the line of code giving the error: A(i,j)=(0.5)*(c)*(Cla).*(C(i,j))+k(i,j) you are using the full matrix c. Maybe you wante...

19 days ago | 0

Answered

Detecting length and number of occurrences in a logical array

Download Jan's RunLength utility from the File Exchange. It will do exactly what you want. array1 = [0 0 0 0 0 1 1 1 1 0 0 1 1 ...

Detecting length and number of occurrences in a logical array

Download Jan's RunLength utility from the File Exchange. It will do exactly what you want. array1 = [0 0 0 0 0 1 1 1 1 0 0 1 1 ...

19 days ago | 0

| accepted

Answered

Dark Mode editor for MATLAB

The best way that I know of to do this is to use MATLAB Schemer from the File Exchange.

Dark Mode editor for MATLAB

The best way that I know of to do this is to use MATLAB Schemer from the File Exchange.

20 days ago | 0

| accepted

Answered

How to terminate the loop

Due to floating-point error, it may be that the condition if p_f_BM == 1 is not exactly met. With floating-point numbers, it's...

How to terminate the loop

Due to floating-point error, it may be that the condition if p_f_BM == 1 is not exactly met. With floating-point numbers, it's...

20 days ago | 0

| accepted

Answered

If I work on a different computer everytime, is there a way to save my shortcut codes (ie all the plot formatting stuff that's always the same) on my math works account so I can pull it up on Matlab?

I think you could probably use MATLAB Drive to do what you want. You could also store your code in a git repository, including ...

If I work on a different computer everytime, is there a way to save my shortcut codes (ie all the plot formatting stuff that's always the same) on my math works account so I can pull it up on Matlab?

I think you could probably use MATLAB Drive to do what you want. You could also store your code in a git repository, including ...

20 days ago | 0

| accepted

Answered

What is the s_rot() function ?

That is not part of base MATLAB or any MathWorks toolbox, as far as I could find. Googling on "s_rot" matlab found a few hi...

What is the s_rot() function ?

That is not part of base MATLAB or any MathWorks toolbox, as far as I could find. Googling on "s_rot" matlab found a few hi...

20 days ago | 1

| accepted

Answered

machine learning for medical data analysis

That is a function from the Image Processing Toolbox. You should check to see if you have that toolbox installed and licensed. ...

machine learning for medical data analysis

That is a function from the Image Processing Toolbox. You should check to see if you have that toolbox installed and licensed. ...

21 days ago | 0

| accepted