41,685 total contributions since 2011

I do not do free private consulting. If you want to bring my attention to something, send a link to the MATLAB Answers location.

Answered

Matrix Randomize with order

There cannot be any solution to this problem. Consider that you have 21 columns. Each "line" (including columns) can have a ma...

Matrix Randomize with order

There cannot be any solution to this problem. Consider that you have 21 columns. Each "line" (including columns) can have a ma...

1 hour ago | 0

Answered

distance between randomly selected nodes

xt = [CC.xd]; yt = [CC.yd]; distances = squareform( pdist([xt(:), yt(:)]) );

distance between randomly selected nodes

xt = [CC.xd]; yt = [CC.yd]; distances = squareform( pdist([xt(:), yt(:)]) );

2 hours ago | 0

Answered

Functions: converting Fahrenheit to Celsius

When you define a function inside a script, the function cannot have the same name as the script .m file.

Functions: converting Fahrenheit to Celsius

When you define a function inside a script, the function cannot have the same name as the script .m file.

2 hours ago | 1

Answered

Plot different functions in the same graph?

plot first function hold on plot second function h3 = plot third function for t = 1 : whatever calculate new X and Y to...

Plot different functions in the same graph?

plot first function hold on plot second function h3 = plot third function for t = 1 : whatever calculate new X and Y to...

2 hours ago | 0

Answered

Matrix dimensions must agree error when converting from jg2 to tiff

fileparts returns character vectors, not string objects. baseFileNameYeet is a character vector. You are trying to do arithmetic...

Matrix dimensions must agree error when converting from jg2 to tiff

fileparts returns character vectors, not string objects. baseFileNameYeet is a character vector. You are trying to do arithmetic...

2 hours ago | 0

Answered

How to integrate within a loop with an interpolating function?

You have x=(-4:0.05:4); y=(-4:0.05:4); [X,Y]=meshgrid(x,y); those put specific numeric arrays into X and Y. Z1=3*(1-X).^2.*...

How to integrate within a loop with an interpolating function?

You have x=(-4:0.05:4); y=(-4:0.05:4); [X,Y]=meshgrid(x,y); those put specific numeric arrays into X and Y. Z1=3*(1-X).^2.*...

2 hours ago | 0

Answered

Plot won't show up for plotting error for SOR method

err = zeros(1,m); for w = 1 : m x = sor1_fn(A,b,w,X0,n_iter); err(w) = norm(x_true - x); end plot(1:m, err);

Plot won't show up for plotting error for SOR method

err = zeros(1,m); for w = 1 : m x = sor1_fn(A,b,w,X0,n_iter); err(w) = norm(x_true - x); end plot(1:m, err);

20 hours ago | 0

Answered

Importing data from a file in a specific way

fileID = fopen(file, 'r'); formatSPec = '%f %f %f'; sizeA = [3 Inf]; %notice not [Inf 3] A = fscanf(fileID, formatSpec, siz...

Importing data from a file in a specific way

fileID = fopen(file, 'r'); formatSPec = '%f %f %f'; sizeA = [3 Inf]; %notice not [Inf 3] A = fscanf(fileID, formatSpec, siz...

20 hours ago | 0

| accepted

Answered

Not enough memory to open .nii file

.nii files are binary files. You should not be trying to edit them in MATLAB. You should use https://www.mathworks.com/help/imag...

Not enough memory to open .nii file

.nii files are binary files. You should not be trying to edit them in MATLAB. You should use https://www.mathworks.com/help/imag...

22 hours ago | 0

Answered

Extract certain rows of matrix if they have a certain number

mask = ismember(M(:,4), 17:21); afternoon_M = M(mask,:); There are other ways to write the test, such as mask = M(:,4) >= 17...

Extract certain rows of matrix if they have a certain number

mask = ismember(M(:,4), 17:21); afternoon_M = M(mask,:); There are other ways to write the test, such as mask = M(:,4) >= 17...

23 hours ago | 1

Answered

Unable to perform assignment because the left and right sides have a different number of elements, Fisheriris

gscatter() returns a number of handles equal to the number of groups it detects. Since you appear to have 8 groups, it will prob...

Unable to perform assignment because the left and right sides have a different number of elements, Fisheriris

gscatter() returns a number of handles equal to the number of groups it detects. Since you appear to have 8 groups, it will prob...

24 hours ago | 0

Answered

How to write binary numbers in a txt file?

The result of dec2bin is a char array. A char array is a single parameter as far as %s is concerned. If you are using R2016b or...

How to write binary numbers in a txt file?

The result of dec2bin is a char array. A char array is a single parameter as far as %s is concerned. If you are using R2016b or...

1 day ago | 0

Answered

How to define a variable form a value in for loop?

This is really not recommended If you insist on doing this not-recommended thing

How to define a variable form a value in for loop?

This is really not recommended If you insist on doing this not-recommended thing

1 day ago | 0

Answered

Can I specify C matrix with tf2ss?

You cannot specify the C matrix in a tf2ss() call. It always calculates the C matrix based upon the numerator and denominator. L...

Can I specify C matrix with tf2ss?

You cannot specify the C matrix in a tf2ss() call. It always calculates the C matrix based upon the numerator and denominator. L...

1 day ago | 1

| accepted

Answered

How to plot function part by part?

duration = 10; Fs = 20; %samples per second secs_per_plot = 2; data = randi([-5 5], 1, duration*Fs); %example data fo...

How to plot function part by part?

duration = 10; Fs = 20; %samples per second secs_per_plot = 2; data = randi([-5 5], 1, duration*Fs); %example data fo...

1 day ago | 0

| accepted

Answered

How does the operation take place for, b (2:6, 2:6) = b(1:5, 2:6) + b(3:7, 2:6) + b(2:6, 1:5) + b(2:6, 3:7); , row-wise manner ?

The first code extracts all the various subsets of the b array before doing any assignments. For example b(3,4) is part of each ...

How does the operation take place for, b (2:6, 2:6) = b(1:5, 2:6) + b(3:7, 2:6) + b(2:6, 1:5) + b(2:6, 3:7); , row-wise manner ?

The first code extracts all the various subsets of the b array before doing any assignments. For example b(3,4) is part of each ...

1 day ago | 1

| accepted

Answered

Undefined function 'initializeParameters' for input arguments of type 'double'. This is what i get when i run. Please help

https://www.mathworks.com/matlabcentral/fileexchange/69238-hyperspectral-image-classification You need to install that. If you ...

Undefined function 'initializeParameters' for input arguments of type 'double'. This is what i get when i run. Please help

https://www.mathworks.com/matlabcentral/fileexchange/69238-hyperspectral-image-classification You need to install that. If you ...

1 day ago | 0

Answered

Index in position 2 exceeds array bounds (must not exceed 3).

Because g includes 4, at some point you are going to try to access l(1,4) . However you only initialize l to (3,3) so l(4,:) and...

Index in position 2 exceeds array bounds (must not exceed 3).

Because g includes 4, at some point you are going to try to access l(1,4) . However you only initialize l to (3,3) so l(4,:) and...

1 day ago | 0

| accepted

Answered

how to append a mat file

You cannot do that with save() Have a look at https://www.mathworks.com/help/matlab/ref/matfile.html

how to append a mat file

You cannot do that with save() Have a look at https://www.mathworks.com/help/matlab/ref/matfile.html

1 day ago | 0

Answered

Passing values to Bash script

Example: cmd = sprintf('alpha=%d beta=%d ls | head -$beta | tail -$alpha', alpha, beta); system(cmd)

Passing values to Bash script

Example: cmd = sprintf('alpha=%d beta=%d ls | head -$beta | tail -$alpha', alpha, beta); system(cmd)

1 day ago | 0

| accepted

Answered

UiTable HTML not working

uitable for app designer is not based upon the same underlying technology, and does not support html for coloring. I do not kn...

UiTable HTML not working

uitable for app designer is not based upon the same underlying technology, and does not support html for coloring. I do not kn...

1 day ago | 0

Answered

Array indices must be positive integers or logical values error

You initialize nT to 0. You access wk(nT) but nT is still 0. You need to move the increments of nT to before you use nT as ind...

Array indices must be positive integers or logical values error

You initialize nT to 0. You access wk(nT) but nT is still 0. You need to move the increments of nT to before you use nT as ind...

2 days ago | 0

| accepted

Answered

Finding value of x using integral

The right hand side is a constant. Compute it first. Suppose I refer to that as RHS. Then you can fsolve(@(Xa) integral(@(XA...

Finding value of x using integral

The right hand side is a constant. Compute it first. Suppose I refer to that as RHS. Then you can fsolve(@(Xa) integral(@(XA...

2 days ago | 0

Answered

How to convert 1x21 array to table

lambda_table = table(labmda(:), 'VariableNames', {'lambda'});;

How to convert 1x21 array to table

lambda_table = table(labmda(:), 'VariableNames', {'lambda'});;

2 days ago | 0

Answered

How to calculate monthly data from daily rainfall data in a time-seris 3-dimensional matrix?

mat2cell() to break the 17 x 22 x 332 up into cell arrays 17 x 22 x number_of_days_in_month . Then you can cellfun(@(M) sum(M,3)...

How to calculate monthly data from daily rainfall data in a time-seris 3-dimensional matrix?

mat2cell() to break the 17 x 22 x 332 up into cell arrays 17 x 22 x number_of_days_in_month . Then you can cellfun(@(M) sum(M,3)...

2 days ago | 0

| accepted

Answered

fsolve problem

It is not possible to set bounds for fsolve() . You can set the FunValCheck option for fsolve() to tell it to check each iterati...

fsolve problem

It is not possible to set bounds for fsolve() . You can set the FunValCheck option for fsolve() to tell it to check each iterati...

2 days ago | 0

Answered

Can I divide a linear array by a number which larger than its size ?

Next20 = @(V) ceil(length(V)/20) * 20; Interp20 = @(V) interp1(V, linspace(1, length(V), Next20(V))); Split20 = @(V) mat2cell(...

Can I divide a linear array by a number which larger than its size ?

Next20 = @(V) ceil(length(V)/20) * 20; Interp20 = @(V) interp1(V, linspace(1, length(V), Next20(V))); Split20 = @(V) mat2cell(...

2 days ago | 0

Answered

Sending <ESC> T over Serial port to Scale

fprintf(s, '%cT', 27) you might also need to send a terminator

Sending <ESC> T over Serial port to Scale

fprintf(s, '%cT', 27) you might also need to send a terminator

3 days ago | 0

Answered

MATLAB code that execute exp function without using the exp inbuilt function

See https://www.mathworks.com/help/fixedpoint/ref/cordiccexp.html

MATLAB code that execute exp function without using the exp inbuilt function

See https://www.mathworks.com/help/fixedpoint/ref/cordiccexp.html

4 days ago | 0

Answered

Index exceeds the number of array elements (2) Error

Your assignment to h(i) after the if expects vt(i) to have been assigned to. However, if the if condition was false, then the as...

Index exceeds the number of array elements (2) Error

Your assignment to h(i) after the if expects vt(i) to have been assigned to. However, if the if condition was false, then the as...

5 days ago | 0