Answered
Partitioning a number into sum of positive real numbers
This is equivalent to partitioning positive integers that sum to 10*M. Download @John D'Errico's excellent partitioning code...

5 years ago | 1

Answered
dbscan clustering of xy points only returns outliers
You actually need to increase epsilon, because you need a larger search radius to identify neighborhood points. load centers i...

5 years ago | 1

| accepted

Answered
Creating a 3D matrix by combination of a 3D matrix and a 2D matrix
I think this does what you want: % Set seed for reproducibility of this example rng(55) % Made-up data of the correct size ...

5 years ago | 0

Answered
Why do I have an error saying "Invalid file identifier"?
I would guess that the value of fileID that is generated is -1, meaning that there was a problem with the fopen function. A like...

5 years ago | 0

Answered
Mathematical operation on arrays
% Set random number seed, for reproducible results in this example rng default % Make up the input data N = 7; a = rand(N,...

5 years ago | 1

Answered
Is it wrong to put 'end' after certain sections, or does the problem lie in other codes?
The first few lines of what you have posted here are not valid MATLAB code. Are you trying to convert from some other programmin...

5 years ago | 0

| accepted

Answered
Repeat a cumulative sum in a matrix
% Made-up data M = rand(2784,252); % Reshape to put each year in a "slice" in the 3rd dimension M2 = reshape(M,2784,12,[]);...

5 years ago | 1

Answered
How to convert FORTRAN files (.F) of before 1990s to MATLAB files ?
You can try f2matlab from the File Exchange. Although it apparently only converts F90 files, the documentation there states tha...

5 years ago | 0

| accepted

Answered
How to create a pivot table from this table (revised)
What you want to do is not really a pivot: % Create your table customer = {'1';'2';'3'}; location = {'NY';'LA';'Austin'}; ge...

5 years ago | 0

Answered
Marker indices for a plot error
The MarkerIndices Name-Value pair is expecting the indices of the data points (e.g. the 1st, 5th, and 10th data point) to place...

5 years ago | 0

Answered
How to run m-file instead of editor open
If you have the MATLAB Compiler, you can create a stand-alone executable of your code. (That is a separate product with addition...

5 years ago | 0

Answered
How to run m-file instead of editor open
If the name of the file is myfile.m, then typing >> myfile (without the >>) in the Command Window should simply execute the fi...

5 years ago | 0

Answered
Reducing the distance among subplot figures?
Not a direct answer to this question, but the newer tiledlayout method has greater flexibility in this regard. (For example, the...

5 years ago | 0

Answered
Insert Matrix into Matrix and don't care if some of the numbers fall off the edge
Probably not the most efficient, but I believe this does what you want: % Arrays A= [1 1 1 1 2 1 1 1 1]; B= [0 0 0 ...

5 years ago | 0

Answered
Creating loop with two variables
You only really need one loop: target = cell(size(j)) for j = 1:12 target{j} = [j j+1]; end or zero loops: j = num2cel...

5 years ago | 0

Answered
Passing variables in string under for loop.
You need to convert the numeric values in the loops into strings. Here is how to construct the string to pass into lt.Cmd: i = ...

5 years ago | 0

Answered
I want to create a function that I can plot
You needed elementwise operations in several places that you did not use it: x = 1:5; y1 = -10.^(0.5.*x) + sin(x) .* abs(x.^3 ...

5 years ago | 0

Answered
Cell Array to output like this?
Here is one way: A = {'0.2','1'} output = cellfun(@str2num,A)

5 years ago | 0

| accepted

Answered
Computing missing values with linear fit
% Set the random number generator seed, for reproducibility rng default % Make up some pretend data N = 10; x = (1:N)'; y...

5 years ago | 1

Answered
How to find n letter strings in an array
X = ["in", "out", "go", "come"]; output = X(strlength(X)==2) The print command is for figures, so I'm not sure what you mean b...

5 years ago | 1

Answered
Array indices must be positive integers or logical values.
Is it possible that you defined a variable called exp? If so, then MATLAB is trying to index into that variable, rather than cal...

5 years ago | 0

Answered
How to sort multiple arrays into bins generated by another array?
If you use the 3rd output of the histcounts function on your data, I believe you'll get the indexing you want, and your other ta...

5 years ago | 1

| accepted

Answered
how to put while loop output in array form
If you have a recent version of MATLAB, this will work: A=[1 4 5 10 9 3 2 6 8 4]; B=[1 7 3 4 1 10 5 4 7 4]; out = A' + B T...

5 years ago | 0

| accepted

Answered
Issue using Mann-Kendall Test
You have NaT values in your timetable. When I removed them with FM1(isnat(FM1.Var2),:) = []; the code ran to completion.

5 years ago | 0

| accepted

Answered
Is there a way to overlay one mask onto another?
I don't really do image processing, but I think this straightforwardly answers your question, using only base MATLAB commands. T...

5 years ago | 0

| accepted

Answered
Plotting different figures by means of for loop
I believe this does what you are trying to do: % Create some fake data [Use your real data instead] m = 5; C = cell(3,4); C ...

5 years ago | 0

| accepted

Answered
matlab not plotting graph
You are using a matrix division operation rather than an elementwise division. So you need, h = [2,4,6,8,10]; x = 10.1; y = 2...

5 years ago | 0

Answered
Numerical function invalid expression
You need the explicit multiplication sign 2*x: h=@(x)exp(2*x).*tan(x)./x.^3 You might also want to put in some parentheses ins...

5 years ago | 1

| accepted

Answered
Find indices in 2D Matrix
Is this what you mean? (I made the matrices smaller, just to show the result.) A = rand(5,2)>.3; B = rand(5,2); newmatrix =...

5 years ago | 0

| accepted

Answered
Efficient way to multiply a vector of size (Nx,1) with a matrix of size (Nx+1,Nx+1)
If you permute gamma to be a vector along the dimension 3, then you can multiply it by identy, and the result will be a 33x33x32...

5 years ago | 1

| accepted

Load more