Answered
How do I set the getkey figure as invisible?
Dear LJM, I am the author of this function. Unfortunately you cannot hide the figure completely as it requires to be modal. H...

8 years ago | 0

Answered
How to get the average duration for consecutive states
You want to do some kind of run-length encoding, for which there are many tools available on the File Exchange. I point you t...

8 years ago | 0

| accepted

Answered
How to plot best fit line?
if it is just for plotting, the command *lsline* would do. x = 1:10 ; y = 2* x + 3 ; plot(x, y, 'bo') ; lsline

8 years ago | 9

Answered
Addition of certain consecutive elements along column in a matrix.
if ~all(sum(A,2)==1) error('invalid input!') end Z = zeros(1,size(A,2)) dA = diff([Z ; A ; Z], 1, 1).' [C,...

8 years ago | 0

Answered
rearrangement of row matrix
*circshift* is your friend. Example: A = 1:10 % your vector N = 5 ; % start at position N B = circshift(A, 1-N)

8 years ago | 0

| accepted

Answered
How can you make a formule where you can input multiple arrays?
Here is a an example that hopefully helps: % fixed input data (or use input function) A = 5 ; B = [10 20 30 40] ; ...

8 years ago | 0

Answered
How to draw vertical lines in between categorical x-axis ticks
Use the average? v = (xNames(5)+ xNames(6))/2 plot([v v], ...) You might also be interested in various utilities on t...

8 years ago | 0

Answered
Nested for loop and cell arrays
help cellfun

8 years ago | 0

Answered
How to use histcounts with struct array?
Welcome to the forum! You can use a loop or arrayfun to extract the scalar value, like: y = arrayfun(@(k) particle(k).co...

8 years ago | 0

| accepted

Answered
I have a multidimensional matrix
Assuming you have 3D matrix of size N-by-M-by-P and you want to concatenate (I assume you meant this by the word add!) another m...

8 years ago | 0

Answered
Find adjacent values of a vector corresponding to another vector
Here is a solution that finds the element in A that is just before or just after each element in B. A=[ 11; 22; 32; 44; 51;...

8 years ago | 0

Answered
selecting i element non overlapping subsets of an array of length n
or you can use a simple for-loop A = 1:10 n = 3 ; N = numel(A) ; for k=1:n:N ix = k:min(k+n-1,N) ; s...

8 years ago | 0

| accepted

Answered
Varying number of nested loops
% small example, last column is result, first columns define combinations DATA = [1 2 4 ; 1 3 15 ; 1 2 6 ; 1 2 8 ; 1 3 25] ...

8 years ago | 1

| accepted

Answered
Random combinations of symbols (restored)
A perfect job for my old RANDP function that picks random values using probabilities :) Objects = 'ABCDEF' probVector...

8 years ago | 0

Answered
creating a matrix where the element of the second column is smaller than the element of the first column
And here is a one-liner (using only MatLab functions). n = 5 ; M = flipud(nchoosek(n:-1:0,2) + [0 1]) % + expansion work...

8 years ago | 0

Answered
creating a matrix where the element of the second column is smaller than the element of the first column
Another approach: n = 7 ; M = [n+1-nchoose2(1:n) ; repmat(1:n,2,1).'] % voila! M_sorted = sortrows(M) % in sorted...

8 years ago | 0

Answered
Replacing same rows with same variables in first to third column
No need for loops at all! Use both outputs of ismember and replace accordingly aa = [1 2 3 7 4 5...

8 years ago | 1

Answered
mean of each column of a cell array that contains cell arrays
Another approach, as all cells contain a column vector: M = arrayfun(@(k) mean([A(k,1) ; A(k,2)]), 1:size(A,1))

8 years ago | 0

Answered
Colours for different bar groups
data = [0.91 NaN 0.65 0.79] % the stacked trick H = barh(1:numel(data), diag(data),'stacked') H(1).FaceColor = 'k' ;...

8 years ago | 0

| accepted

Answered
Deleting missing values (different amount and distribution of NaNs for each column)
You cannot concatenate different length vectors into a single matrix. You could store each column of A into a separate cell ...

8 years ago | 0

| accepted

Submitted


nearestpoint(x, y, m)
NEARESTPOINT - find the nearest value in another vector

8 years ago | 1 download |

4.9 / 5
Thumbnail

Answered
Create Legend From Array
In the first two codes, legendCell is a cell array of cells ( = {{..} {...}} ) rather than a cell array of strings (= {'..' '....

8 years ago | 2

| accepted

Answered
Find elements from A in B and get the index of found element in B
I think you'll find my function NEARESTPOINT pretty helpful in this respect. You can download it from the File Exchange: <htt...

8 years ago | 0

Answered
Naming a structure with a string that was fetched through x=input(prompt)
You do not want to do that. It should be the *contents* of a variable that is flexible and not the name. Assuming you want to st...

8 years ago | 2

| accepted

Answered
How do I create every sum of column entries of a m x n matrix?
A = magic(3) [m,n] = size(A) % get the row indices into A for every combination clear r [r{n:-1:1}] = ndgrid(1...

8 years ago | 0

Answered
How do I create every sum of column entries of a m x n matrix?
read the help of sum, and take a look at the dimension argument help sum M = randi(10,3,4) sum(M,1) % sum a...

8 years ago | 0

Answered
Finding cells with specific string in cell array and substituting them
You can simply use *strrep* to replace strings in a cell array: CC = {'A',' -','B',' -','C'} CCout = strrep(CC,' -', '0'...

8 years ago | 1

| accepted

Answered
How to i get combination of 4 non-consecutive numbers?
To make Walters' solution flexible, you can use a=[2 4 6] N = 3 ; clear T [T{N:-1:1}] = ndgrid(a) output = ...

8 years ago | 1

Answered
Find elements from A in B and get the index of found element in B
You want to find all the indices of all elements of A in B? So, some elements of A might occur once, other multiple times, and s...

8 years ago | 0

| accepted

Answered
How do you check if all the values in a vector are in another vector as many or more times?
a = [1 1 3 4 4] b = [4 7 3 3] [bu,~,j] = unique(b) ; n_present = countmember(bu,a) ; n_needed = accumarray(j,1).'...

8 years ago | 0

Load more