Answered
How to repeat letter presented two steps before?
This seems to be some kind of homework assignment (which is fine!) so I will just give you some thoughts: # You have a set X ...

8 years ago | 0

Answered
How do I split a folder with images into two folders with images using MATLAB?
# retrieve all filenames using *dir* # create a random logical vector with 70% true, e.g. *tf = randperm(N) > (0.70 *N)*, where...

8 years ago | 2

Answered
I have a vector that is the combination of 2 data sets alternating every n data points. How do I separate these into their own vectors?
You can use logical indexing to separate the two sets, and NaNs to separate the plotted segments: % data data = cumsum(r...

8 years ago | 0

| accepted

Submitted


randpermmat(N, M)
Random permutation matrix

8 years ago | 1 download |

0.0 / 5
Thumbnail

Answered
how to create a square matrix with unique real values?
A very simple one-liner will do the trick: N = 10 ; [~, A] = sort(rand(N), 2)

8 years ago | 1

Answered
Can I save my outputs in a way to use them as my inputs for the next run?
Assuming the function above in a m-file, called _MyFunction.m_ function [C,D] = MyFunction (A,B) C = A*B ; D = A+B ;...

8 years ago | 0

| accepted

Answered
Index same value numbers in array
I offer you my function *runindex* which does exactly this, fast and vectorised! A = [1 1 1 5 5 8 9 9 9 9 10 11] B = run...

8 years ago | 0

Answered
In a Matlab plot(x,y) having both negative and positive 'y' values, how to display the xtick labels at zero(0) line too
The word too implies showing the tick labels twice ... This just repositions the axis, which is what you're after, I think: ...

8 years ago | 0

Answered
second condition never gets executed - elseif (temp == 13.2) tried to run in 13b, 15b online edittors as well, any explanations or its a bug?
Welcome to the world of computers where it is tricky to compare floating point numbers. Take a look at the answer here: <https:/...

8 years ago | 3

Answered
How to effectively run loops and save time in computation? I have a matrix of size 'm' and run five loops from 1 to m. The logic is explained below. How to optimize the code and save time of calculation.
A few observations: # you should pre-allocate x, y and output before the loops # H(i,k) + H(j,k) equals H(j,k)+H(i,k), so yo...

8 years ago | 0

Answered
How to remove certain elements of an array but keep original indices of elements that are kept
Time toe learning about logical indexing! x = [3 -1 -1 5 -1 -1 -1 8 2 -1 -1 9] tf = x ~= -1 idx = find(tf) y = x(t...

8 years ago | 1

| accepted

Answered
is there any way that can speedup the process of following code... A and B are 50000x20 matrices..?
Your looking for corresponding rows in A and B. *intersect* might help you [~,ia,ib] = intersect(A(:,1:7), B(:,1:7), 'rows'...

8 years ago | 1

| accepted

Answered
How do I ensure random generates different samples each trial?
Executing rand (or random or randi) will return new random numbers, uncorrelated to previously retrieved numbers (unless you see...

8 years ago | 0

Answered
How to normalize the sine wave for the given code below?
y_normalised = 2*(y - mean(y)) ./ range(y) ; or set the amplitude to 1 instead of t when you create the sinewave?

8 years ago | 0

| accepted

Answered
How do I fit an exponential equation to raw data
This should get you started: % some data x = 1:20 ; y = exp(-10 ./ (x .^ 1.1)) ; yr = y + randn(size(y))/10 ; % ad...

8 years ago | 1

| accepted

Answered
programming the number of steps till every element of a set appears
What have you tried so far, perhaps in writing some pseudocode, or making a flowchart? *randi* and *while* are functions that...

8 years ago | 0

Answered
All combinations from a set of rows without repetition of elements
You might be interested in a faster alternative for nchoosek(n,k) when k equals 2: <https://uk.mathworks.com/matlabcentral/fi...

8 years ago | 0

Answered
remove pixels with certain rgb values
Is I really a 3D array or is the third dimension just 1? Simply take a look at the value of rgb, after the size(I) command :)...

8 years ago | 1

Answered
Concentric circles with different colors
You can specify a colormap beforehand: R = 30:-5:5 ; % radii N = numel(R) ; % Cmap = parula(N) ; % one of the many a...

8 years ago | 0

Answered
How to calculate euclidean distance between two feature vectors
Take a look at * *norm** EuclideanDistance = norm(vec2-vec1, 2)

8 years ago | 2

Answered
How can I save my plots with file names from a string in my loop?
Add '.fig' to each filename saveas(h, [filenames{k+3} '.fig'], 'fig') Also try to reconsider your approach when you add ...

8 years ago | 0

| accepted

Answered
How to get cumsum to work on consecutive values and restart if there is a 0 value?
Here is a rather easy approach: G = [ 0 0 1 1 1 0 0 0 0 1 1 1 1 1 1 1 0 NaN 0 NaN 0 9 9 9 9] % data ix = cumsum([true di...

8 years ago | 3

Answered
change the dimension of multidimensional matrix
Maybe you're looking fo cell arrays, in which each cell can hold a vector of different lengths? As an example: Nrows = 1...

8 years ago | 0

Answered
How to add plot titles in a for loop
You use the wrong format identier (%d) in sprintf,, which should be %s: X = 'Jasper' sprintf('Hello %s!', X) (and you...

8 years ago | 2

| accepted

Answered
Sample of sine wave
Something along these lines? t = linspace(0,2*pi,1000) ; y = 100 * sin(2*pi*1.8*t) ; s = sort(randperm(numel(t),1...

8 years ago | 1

| accepted

Answered
How to add or multiply two different size of array using the loop iteration process?
a = [1 2 3 4 5 6 7 8 9 ] b = [1 2 3 4] % Generic case: numel(a) is not a multiple of numel(b) nb = num...

8 years ago | 0

Answered
How to generate a random noise with increasing amplitude?
Something like this? N = 1000 ; t = linspace(0,5,N) ; % seconds y = 10*sin(2*pi*0.5*t) ; % signal MaxNoise = 4...

8 years ago | 0

| accepted

Answered
how to delete this error?
or even shorter y = ~x

8 years ago | 2

Answered
move all zeros to the right in a matrix
Here is one way: % data X = [1 2 3 0 4 ; 1 0 0 0 2 ; 1 0 2 3 4 ; 1 2 3 0 0 ; 0 0 0 0 1] % engine X = X.' ...

8 years ago | 0

Answered
Sum if multiple conditions satisfied across different arrays
% data S = randi([0 1],4,10) % state matrix adj = [0 1 1 1 ; 1 0 0 1 ; 1 0 0 1 ; 1 1 1 0] % adjacency matrix (symmetric...

8 years ago | 1

| accepted

Load more