Solved

Return a list sorted by number of consecutive occurrences

Inspired by Problem 38 by Cody Team. Given a vector x, return a vector y of the values in x sorted by the number of CONSECUTIVE...

alrededor de 18 horas ago

Solved

Replicate elements in vectors

Replicate each element of a row vector (with NaN) a constant number of times. Examples n=2, A=[1 2 3] -> [1 1 2 2 3 3] ...

alrededor de 19 horas ago

Solved

Get the elements of diagonal and antidiagonal for any m-by-n matrix

In the problem <http://www.mathworks.com/matlabcentral/cody/problems/858-permute-diagonal-and-antidiagonal Problem 858. Permute ...

alrededor de 19 horas ago

Solved

Getting the indices from a matrice

Getting the indices from a matrice. Inspired by Problem 645. Getting the indices from a vector by the great Doug Hull. Given a...

alrededor de 19 horas ago

Solved

Set the array elements whose value is 13 to 0

Input A either an array or a vector (which can be empty) Output B will be the same size as A . All elements of A equal to 13...

alrededor de 19 horas ago

Solved

Construct an index vector from two input vectors in vectorized fashion

Create an index vector defined by two input vectors, one defining the beginnings of one or more index ranges, and the other defi...

alrededor de 19 horas ago

Answered

create a new 4D Array from 2 others

I think I understand what you mean. The code below will overwrite all values that are not NaN for a given depth, which is equiva...

create a new 4D Array from 2 others

I think I understand what you mean. The code below will overwrite all values that are not NaN for a given depth, which is equiva...

alrededor de 21 horas ago | 0

| accepted

Answered

Generating a random number from array based on requirements

A=[1,2,3,4]; p=[10 20 30 40]; c=cumsum(p); isAllowed=[3,4]; while true [~,r]=histc(rand(1,1),[0 c/c(end)]); if ism...

Generating a random number from array based on requirements

A=[1,2,3,4]; p=[10 20 30 40]; c=cumsum(p); isAllowed=[3,4]; while true [~,r]=histc(rand(1,1),[0 c/c(end)]); if ism...

1 día ago | 0

Answered

Graph window is blank

As most of the operation you perform don't work for most shapes of input data, I'm assuming you're calling this code with scalar...

Graph window is blank

As most of the operation you perform don't work for most shapes of input data, I'm assuming you're calling this code with scalar...

1 día ago | 0

Answered

How to write this for loop as a while

Every for-loop can be re-written to a while-loop. y = 0; k = 1; while k<=999 y = y + k*k; k = k + 4; end

How to write this for loop as a while

Every for-loop can be re-written to a while-loop. y = 0; k = 1; while k<=999 y = y + k*k; k = k + 4; end

1 día ago | 1

Answered

Modifying odd/even numbers of a column vector

If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks). x ...

Modifying odd/even numbers of a column vector

If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks). x ...

1 día ago | 0

| accepted

Answered

Multi Dimension Matrix Elements multiplication

Not completely without loops, but this should be fast enough. You should also be aware that loops can sometimes be the fastest w...

Multi Dimension Matrix Elements multiplication

Not completely without loops, but this should be fast enough. You should also be aware that loops can sometimes be the fastest w...

1 día ago | 0

Answered

How to run function between each row

pairs=nchoosek(1:size(data,1),2); for n=1:size(pairs,1) row_a=data(pairs(n,1),:); row_b=data(pairs(n,2),:); %cal...

How to run function between each row

pairs=nchoosek(1:size(data,1),2); for n=1:size(pairs,1) row_a=data(pairs(n,1),:); row_b=data(pairs(n,2),:); %cal...

2 días ago | 0

Answered

Single line plot with fixed axis

Every axes object has an XScale property you can set to 'log' to get the desired plot. You can use the normal plotting tools (e....

Single line plot with fixed axis

Every axes object has an XScale property you can set to 'log' to get the desired plot. You can use the normal plotting tools (e....

2 días ago | 1

| accepted

Answered

How to click points in a figure to generate a function/set of data?

I would suggest getpts, although there is an alternative that gives visual feedback: ginput.

How to click points in a figure to generate a function/set of data?

I would suggest getpts, although there is an alternative that gives visual feedback: ginput.

2 días ago | 0

Answered

how to generate 10^6 random binary values consisting only -1 and 1?

doc randi

how to generate 10^6 random binary values consisting only -1 and 1?

doc randi

2 días ago | 0

Answered

matrix step shift in each row

This method works without a loop. A =[ 1 2 3 4 5 ]; [X,Y]=ndgrid(1:numel(A)); X=X(end:-1:1,:); ind=mod(...

matrix step shift in each row

This method works without a loop. A =[ 1 2 3 4 5 ]; [X,Y]=ndgrid(1:numel(A)); X=X(end:-1:1,:); ind=mod(...

3 días ago | 0

| accepted

Answered

Nothing will be showing on plot

You are plotting single points, without changing the default (where points are not displayed, only the line connecting them). Yo...

Nothing will be showing on plot

You are plotting single points, without changing the default (where points are not displayed, only the line connecting them). Yo...

3 días ago | 0

Answered

How can I calculate the revenue in a FOR loop?

Store the revenue in a vector you index with s. Then use sum to calculate the total.

How can I calculate the revenue in a FOR loop?

Store the revenue in a vector you index with s. Then use sum to calculate the total.

6 días ago | 0

Answered

Form a Matrix dependent of iterations

I'm going to assume your question is a homework assignment. That is why I will ignore the requirement of using a while loop, as ...

Form a Matrix dependent of iterations

I'm going to assume your question is a homework assignment. That is why I will ignore the requirement of using a while loop, as ...

7 días ago | 0

Answered

how to save each array's results in dependent blank in GUI program base code?

For general advice and examples for how to create a GUI (and avoid using GUIDE), have look at this thread. Below I show you some...

how to save each array's results in dependent blank in GUI program base code?

For general advice and examples for how to create a GUI (and avoid using GUIDE), have look at this thread. Below I show you some...

7 días ago | 0

| accepted

Answered

How to detect certain pixel value in a stick.

Something like this will do it: A=imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/524729/image.png'); ...

How to detect certain pixel value in a stick.

Something like this will do it: A=imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/524729/image.png'); ...

7 días ago | 0

| accepted

Answered

Bar graph labels not aligning with index value

You need to set the location of the xticks as well, otherwise Matlab will use the current xticks and use your provided labels in...

Bar graph labels not aligning with index value

You need to set the location of the xticks as well, otherwise Matlab will use the current xticks and use your provided labels in...

7 días ago | 0

Answered

Get Data from a 16414x6 array to 365 arrays with size(48x3)

I would suggest using a 3D array instead. If you dynamically generate variable names you are shooting yourself in the foot. You ...

Get Data from a 16414x6 array to 365 arrays with size(48x3)

I would suggest using a 3D array instead. If you dynamically generate variable names you are shooting yourself in the foot. You ...

7 días ago | 1

Answered

zoom X axis only - app designer

Your app is a uifigure, so you can test this outside of AppDesigner. It turns out you need to be fairly specific with your handl...

zoom X axis only - app designer

Your app is a uifigure, so you can test this outside of AppDesigner. It turns out you need to be fairly specific with your handl...

7 días ago | 0

Answered

plotting a graph error

What happens if you execute this? clc,type newplotwrapper I'm not sure I'm allowed to share the contents of this file, but it ...

plotting a graph error

What happens if you execute this? clc,type newplotwrapper I'm not sure I'm allowed to share the contents of this file, but it ...

7 días ago | 0

Answered

How to solve "Matrix index is out of range for deletion." error?

Take a look at the indices on the second line: i=1; ind=(6*(i-1))+1:(6*(i-1))+6 Since you use them to index the columns (the ...

How to solve "Matrix index is out of range for deletion." error?

Take a look at the indices on the second line: i=1; ind=(6*(i-1))+1:(6*(i-1))+6 Since you use them to index the columns (the ...

9 días ago | 0

Answered

Can someone explain me how to make this loop efficiently?

Your intuition is correct; this can indeed be simplified: for k=1:numel(SomeArray) if idx <= (k*B) Array...

Can someone explain me how to make this loop efficiently?

Your intuition is correct; this can indeed be simplified: for k=1:numel(SomeArray) if idx <= (k*B) Array...

9 días ago | 1

Answered

Saving a plot as png 224*224*3 image

You can do three things: Don't create your image as a plot, but as an image. Crop the image down to the location of your axes ...

Saving a plot as png 224*224*3 image

You can do three things: Don't create your image as a plot, but as an image. Crop the image down to the location of your axes ...

9 días ago | 0