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!