Risposto
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 ...

circa 8 anni fa | 0

Risposto
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...

circa 8 anni fa | 2

Risposto
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...

circa 8 anni fa | 0

| accettato

Inviato


randpermmat(N, M)
Random permutation matrix

circa 8 anni fa | 1 download |

0.0 / 5
Thumbnail

Risposto
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)

circa 8 anni fa | 1

Risposto
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 ;...

circa 8 anni fa | 0

| accettato

Risposto
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...

circa 8 anni fa | 0

Risposto
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: ...

circa 8 anni fa | 0

Risposto
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:/...

circa 8 anni fa | 3

Risposto
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...

circa 8 anni fa | 0

Risposto
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...

circa 8 anni fa | 1

| accettato

Risposto
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'...

circa 8 anni fa | 1

| accettato

Risposto
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...

circa 8 anni fa | 0

Risposto
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?

circa 8 anni fa | 0

| accettato

Risposto
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...

circa 8 anni fa | 1

| accettato

Risposto
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...

circa 8 anni fa | 0

Risposto
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...

circa 8 anni fa | 0

Risposto
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 :)...

circa 8 anni fa | 1

Risposto
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...

circa 8 anni fa | 0

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

circa 8 anni fa | 2

Risposto
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 ...

circa 8 anni fa | 0

| accettato

Risposto
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...

circa 8 anni fa | 3

Risposto
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...

circa 8 anni fa | 0

Risposto
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...

circa 8 anni fa | 2

| accettato

Risposto
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...

circa 8 anni fa | 1

| accettato

Risposto
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...

circa 8 anni fa | 0

Risposto
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...

circa 8 anni fa | 0

| accettato

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

circa 8 anni fa | 2

Risposto
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.' ...

circa 8 anni fa | 0

Risposto
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...

circa 8 anni fa | 1

| accettato

Carica altro