Answered
Fastest pairwise row sums
% An old-school 20th century indexing trick: A = randi(9,3,2) B = 100*randi(9,4,2) [ia, ib] = ndgrid(1:size(A,1),1:size(B,1...

7 years ago | 0

Answered
Quickly create a vector of ones and zeros
N = 10 % final length of NewVec pos1 = 3 % start index of the 1's n1 = 4 % number of 1's % one-liner. NewVec should...

7 years ago | 0

Answered
how to load values of two matrices into one matrix?
Many roads to Rome, which all learn you about using transpose, reshape, concatention, and/or clever indexing H1 = reshape([A B]...

7 years ago | 0

Answered
Compute difference between rows
I do not understand where A and B come from but this gives the differences between all combinations of 2 rows of the matrix M. ...

7 years ago | 1

| accepted

Answered
How to extract sequential submatrices
Do not create 13 different variables, but store the result in 13 cells of a cell array, by applying MAT2CELL

7 years ago | 0

Answered
Converting a 4d vector to 2d vector
Y = randi(10,1,1,3,4) Y2 = squeeze(Y) % remove singleton dimensions help squeeze

7 years ago | 0

| accepted

Answered
choose 2 random unique element inside cell
If I understand you correctly, the final output should have 8 unique numbers, in four groups of two, where the numbers in each g...

7 years ago | 0

Answered
Deletion of array value in both positions of separate arrays dependent upon the range of one array
A few remarks: 1. what if result is exactly +3 or -3? (you might want to use <= rather than <) 2. replace the two ELSE...

7 years ago | 0

Answered
How to increment from 1 to 0.0000000001 (9 zeros) in 11 rows, 1 column (divide by 10 each time)
format long % for display purposes only v = 10.^(0:-1:-10).'

7 years ago | 1

Answered
Making Different Length Vector Same Length
[EDITED] This might work for you: ix = linspace(1, numel(stress), numel(strain)) NewStrain = interp1(ix, strain, 1:numel(str...

7 years ago | 0

Answered
Hi. I am a complete novice at matlab and have been asked to create a 10x10 matrix in as few steps as possible. The first row has to be from 1:10, the second line from 2:11 and so on. How can I create this using repmat?
I think this is the only acceptable answer is, given all restraints: A = reshape([1:10 2:11 3:12 4:13 5:14 6:15 7:16 8:17 9:18 ...

7 years ago | 0

Answered
how to make a row matrix from matlab generated data.
reshape(S,1,[]) % row vector

7 years ago | 0

| accepted

Answered
How to avoid having duplicate index result?
This also produces the N! possibilities. No loop, no sub2ind, only the outcome of perms as column indices ... N = 4 X = eye(N)...

7 years ago | 0

Answered
How to truncate the image values ??
X = randn(5,5) a = 0, b = 1 % truncate values of X between a and b Xt = min(max(X,a),b) % scale values of X between a and b...

7 years ago | 0

Answered
Return matrix of maximum values
maxxy = zeros(3, 2) ; % pre-allocation for k = 1:3 [~, r] = max(M(:, k+2)) ; % row of maximum value in column k maxxy...

7 years ago | 0

Answered
How to create a matrix with arbitrary dimensions
To create an zero array of an arbitray dimensions between 1 and D with arbitry sizes between 1 and S : D = 10 ; S = 6 ; X = a...

7 years ago | 0

| accepted

Answered
Accumulating Unique Set Values
My suggestion: first find the unique rows of Fset, and then get the column indices for each row FSet = randi(2,10,3) -1 % examp...

7 years ago | 1

| accepted

Answered
How to calculate a rotation matrix between two 3d points
You can used dot and cross products to get the rotation matrix: % two random 3D vectors p0 = randi(10,3,1) p1 = randi(10,3,1)...

7 years ago | 5

| accepted

Answered
How to import mixed .txt - file in a table, with text as comment on first 3 rows and then numeric data with headers?
Make it a two-step process! First, read the first comment lines using FOPEN and FGETL. See the help of FGETL for an example. Do...

7 years ago | 0

| accepted

Answered
Center text on screen
% put a small x in the center of a new figure figure('menubar','none') ; ah = gca ; th = text(1,1,'X') ; set(ah,'visible','o...

7 years ago | 0

| accepted

Answered
find row with certain value and put in cell
result = arrayfun(@(k) unique(B(A(:,k)==1,:)).', 1:size(A,2), 'un', 0)

7 years ago | 0

| accepted

Answered
How can I equate all values of one vector to another and get the value ? Please find the example below
You can use logical indexing, a very powerful tool in Matlab tf = dataB == 7 dataA(tf)

7 years ago | 0

Submitted


nones
fill each row/column with a certain number of ones (N-ONES)

7 years ago | 1 download |

0.0 / 5
Thumbnail

Submitted


SLM
special linear matrix

7 years ago | 1 download |

4.8 / 5
Thumbnail

Submitted


ranknum
compute the rank number (rankings) of elements

7 years ago | 2 downloads |

5.0 / 5
Thumbnail

Answered
Ranking Numbers based on Size
Another, computationally simpler option: A = [1 5 0 9 6 4] [~, R] = sort(A) ; R(R) = 1:numel(A)

7 years ago | 0

Answered
Ranking Numbers based on Size
A = [1 5 0 9 6 4] [~, ~, R] = unique(A)

7 years ago | 0

| accepted

Answered
How can I subtract consecutive numbers from one starting point?
L = 1:4 SP = 200 R = SP - cumsum(L)

7 years ago | 2

| accepted

Submitted


circulant
(yet another, but fast) Circulent Matrix

7 years ago | 1 download |

5.0 / 5
Thumbnail

Submitted


getkey
Get a keypress

7 years ago | 4 downloads |

4.7 / 5
Thumbnail

Load more