How do I create range of random elements for a single element in MATLAB?

I have a 21 x 21 matrix and needing to generate 1-120 random observations (milliseconds) for each element in the array

5 Comments

can you elaborate more? How many times different matrix generate in ms gap of time?
Need to generate new matrix having elements values 1 to 120?
calculate the voltages of a circuit at all locations for all milliseconds up to the 120th millisecond. I'd imagine setting a min & max range in milliseconds and generate 1-120 random observations ?? is a vector of voltages at millisecond ? (?1 -?120)
  • Is there any range of values (elements)?
I have a 21 x 21 matrix of voltage readings at certain junctions in a microchip start from an initial voltage distribution and then calculating the voltage at later points in time.(?1 -?120) I'm stuck I am at this point but cant see how to generate 1-120 obsevation fro each element in the matrix
xmin= 0.001
xmax= 0.12
n=21
A3 = xmin + rand(21,n).*(xmax-xmin);
I have updated the answer, pls check.

Sign in to comment.

 Accepted Answer

%Still not getting the exact question, are you looking for this one?
%x1-Min voltage value x2-Max voltage value
clc;clear;close all;
v=randi([0 1], 21 , 21);
for i=1:120
x=(0.12-0.001).*rand(1,1) + 0.001;
v(:,:)=x
pause(0.001);
end

11 Comments

  • This code generates one matrix of 21x21 order in each 1ms interval.
  • That means each element having 120 values array range with min 0.001 and max 0.12.
Thanks I want to Calculate voltages for 120 miliseconds: ?1 up to ?120 The code has an error Error using randi First input must be a positive scalar integer value IMAX, or two integer values [IMIN IMAX] with IMIN less than or equal to IMAX.
I have updated the answer, pls check.
To bettr explain it would be
[1,1]*randi[v1:v120]
[1,2]*randi[v1:v120]
[1,3]*randi[v1:v120]
etc
Its OK, my code generates(1ms time gap) 120 times matrixes(v) of the order of 21x21, each element of the matrix range from 0,001(min vol) to o.12(max vol), Maybe there is some other way to crack it more easily, but what I understand it, code works same. good Wishes
It means v(1,1) having 120 values form 120 matrixes..similar v(1,2)..so on..What you asked. Otherwise go for 3D matrix
Thanks the trick now is multiplying each observation by the relevant element in the 21 X 21
a = 0.001;
b = 0.12;
A2 = A1 + (b-a).*rand(21,1);
I can generate singular value but for 21 x 21?
If one v matrix is done, generate another after 1 ms, that why I have used for loop to creates 120 v in 1ms gap, see there is pause line.
Are you saying I need to do that 120 times ie pause(0.002, 0.003 , 0.004) etc? or take the pause command out?
No, within for use pause(0.001) that only, please note it creates one matrix simultaneously, next v after 1ms.
Kaylan Thankyou I brought the 21 x 21 Matrix A1 into your syntax and removed the pause condition and it worked.
v=randi([0 1], 21 , 21);
for i=1:120
x= A1 + (0.12-0.001).*rand(1,1) + 0.001;
v(:,:)=x
end

Sign in to comment.

More Answers (0)

Products

Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!