Error using randi (first input must be a positive integer scalar value)
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Rik
am 8 Mär. 2018
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!