Error using randi (first input must be a positive integer scalar value)
조회 수: 6 (최근 30일)
이전 댓글 표시
veri = readtable ('gh.csv');
vericell = table2cell(veri);
ghcolumn = cell2mat(vericell(:,3));
veri.Class = discretize(veri{:, 3}, min(veri{:, 3}):20:max(veri{:, 3})+20);
vericell = table2cell(veri);
class = cell2mat(vericell(:,end));
for ii=1:51
deneme{ii,:}=vericell (class==ii,:);
deneme{ii,:}=cell2table(deneme{ii});
for j = 4:15
deneme{ii}{:,j};
meanres(ii,j) = mean (deneme{ii}{:,j});
stdres(ii,j) = std(deneme{ii}{:,j});
maxres(ii,j) = max(deneme{ii}{:,j});
minres(ii,j) = min(deneme{ii}{:,j});
end
end
vericell = cell2table(vericell);
for cc = 4:15
maxofcolumn(:,cc) = max(vericell{:,cc});
minofcolumn(:,cc) = min(vericell{:,cc});
end
A = table2array(vericell(:,4:15));
for nn = 1:12
randomfor(:,nn) = randi([max(A(:,nn)),min(A(:,nn))]);
end
I am getting First input must be a positive scalar integer value IMAX, or two integer values [IMIN IMAX] with IMIN less than or equal to IMAX error while I am trying to get a random number for each column.
댓글 수: 0
채택된 답변
Rik
2018년 3월 8일
As the error message said, the values must be integers in increasing order. Your original code did not have the correct order, and apparently the values are not integers. You shouldn't convert them to strings, you should round them, but which method of rounding works for you is for you to decide. The code below is one example of how you can ensure you're using a valid syntax.
rand_range=[max(A(:,nn)),min(A(:,nn))];
rand_range=[ceil(rand_range(1)) floor(rand_range(2))];
%if rand_range=[0.1 0.8]; this rounds it to [1 0], so sort to make sure the order is correct
rand_range=sort(rand_range);
randomfor(:,nn) = randi(rand_range);
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!