Randi command for a matrix
조회 수: 5 (최근 30일)
이전 댓글 표시
i am using a random generator for a matrix.
However the randi command is not working for matrix C with following 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.)
clear all
clc
A = (textread('data_mat_ta01_11x5.txt'))'
size(A)
B=A/9
C=floor(B)
D=randi(C)
댓글 수: 0
답변 (1개)
KALYAN ACHARJYA
2019년 9월 19일
편집: KALYAN ACHARJYA
2019년 9월 19일
Wrong here,you read a txt file as A and Divide it by 9>>B, Is there any sense??
% Read a text file, variable name A
A = (textread('data_mat_ta01_11x5.txt'))'
size(A) % No use, you have not assigned to any variable
B=A/9
and
floor rounds each element of B to the nearest integer less than.
Regarding randi matrix generation: See the following example
%...........[3,4] reperesent the size of the required matrix
>> randi(10,[3,4]);
%........^Max element value in the matrix
ans =
9 10 3 10
10 7 6 2
2 1 10 10
Rquested you to debug the code, line by line and modify it accordingly. If you are just a beginner on Matlab, I suggested you to go through this
Good Wishes!
댓글 수: 2
Walter Roberson
2019년 9월 20일
You cannot pass an 11 x 5 array as the first parameter to randi().
D = arrayfun( @(c) randi([1 c]), C);
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!