Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
How can I create a matrix of a size 50 x 50 in MATLAB and each column vector of matrix i.e., 50 x 1 size must have random numbers within a given range and then range for the next column vectors must decrement by k until last column vector is reached?
A solution may be to generate two matrices:
A 50x50 matrix containing random values between 0 and 1
A 50x50 matrix containing the upper limits for each cell
The elementwise multiplication of both matrices should give you the desired matrix.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
how to randomly select an element from an array having the least probability in matlab
example :
A = [ 1,2,3,4,5,6]
P = [ 0.01,0.2,0.25.0.2,0.25,0.09] % probability %
Find all indices of the minimum probabilities. Then generate a random interger depending on the number of equally minimum probabilities. Then use matrix indexing to extract a random index of minimum probability and then its corresponding element.
[~, ind] = mink(P,2); %All indices of minimum elements
Result = A(inds(randi(numel(inds)))); %Random minimum element
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am new to MATLAB and I want to create a random n*n matrix containing just -1 OR 1 as values.
any help ?
I would use randi
% Generate random array of 0s and 1s, *2 and -1 to give random values -1 or +1
m = randi([0,1], n)*2-1
See also: introductory docs on random integers.
I typically use randi to generate the indexes of the numbers I am interested in. E.g. in your case you are interested in the numbers
a= [-1,1];
Thus we use
b = randi(length(a),2,2); %Generate matrix of size 2x2
to generate a random set of indexes. Finally we simply convert the indexes to the numbers of interest.
c = a(b); %Now a 2x2 matrix of -1, 1 numbers
A=rand(n);
thres=rand(1); % or whatever percentage
A=A>thres; % 1 and 0
A(A==0)=-1; % makes 0 -1
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm creating a matrix in matlab of size n that contains only ones and zeros. The easiest way to do that is round(rand(m,n)) for a matrix of size mxn, but it creates in some cases rows that have all zeros or all ones. I want to put a lower and upper bound in the number of ones that each row has. Is there an easy way to do that?
Thanks
This is just for one column, but can easily be extended to a matrix:
v = zeros(m,1); % column
Fill the beginning of the column with at least 40% and at most 60% ones:
v(1: floor((0.4+(0.6-0.4)*rand())*(m+1))) = 1;
Shuffle the column:
v = v(randperm(numel(v)));
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
i want to show the difference value between pixels in same position in successive frames (for example 100 frames),
is it possible to use standard deviation value for determine the number of pixels above or below of this value in successive frames for each pixel position?
or is there another method to show the value of pixels difference in same position in successive frames?
If your image data is the same dimension for each frame, then you can simply concatenate all of your data along a given dimension. Below I will use the 4th dimension since your data may actually be RGB data.
% Assumes that your input data is a cell array of images
combined = cat(4, images{:});
The dimension of this data is now [nRows, nColumns, nChannels, nTime].
Then you can specify the dimension in which to apply many operations in MATLAB. For example if you want to find the differences over time you could use the diff function (Note the specification of the 4th dimension as the third argument):
differences = diff(combined, [], 4);
Similarly you could compute the standard deviation of a pixel over time (Again specifying that you want standard deviation along the 4th dimension).
std_over_time = std(combined, 0, 4);
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Suppose we have some large matrices that want to classify.
If matrices are MN, is it OK to have a neural network with MN neurons that is, for each element a neuron ? Is there any better idea? Actually, in my case, I have 50 matrices with 200 rows and 200 columns [ 200*200 ].
{The elements of input matrices are 0 and 1 }
Thank you in advance.
Find a suitable value for the number of hidden nodes, H, by trial and error.
Create numH*Ntrials plus An outer loop H = Hmin:dH:Hmax over number of hidden nodes and an inner loop i = 1:
Ntrials over number of random trn/val/tst data divisions and random weight initialization trials for each value of H.