필터 지우기
필터 지우기

storing values in Arrays

조회 수: 1 (최근 30일)
Muhammad Naveed Iqbal
Muhammad Naveed Iqbal 2015년 6월 4일
답변: Guillaume 2015년 6월 4일
I want to store different values of t in I but I can't store via this code please help me
for j=0:4
U2 = makedist('Uniform','lower',200,'upper',600);
t=random(U2)
t=round(t)
I(:,j)=t
end

답변 (2개)

Walter Roberson
Walter Roberson 2015년 6월 4일
You started j as 0 and try to store into I(:,j) so you are trying to store in column 0. Matlab array index start at 1

Guillaume
Guillaume 2015년 6월 4일
Well, you can't use a value of zero (the first value j will have) to index into a matrix. Indices must be strictly positive integer. The simplest fix is to have j go from 1 to 5.
The whole line I(:, j)=t is very suspicious. t is scalar, so why have you got a colon (which would indicate you intended to store a vector)? I'd recommend you go through the tutorial to understand indexing.
Note that if all you want to generate is 5 integers between 200 and 600 using a uniform distribution, then randi is much simpler:
I = randi([200 600], 1, 5)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by