我想在Matlab中define(function (require) {
'use strict';
var vue = require('vue');
return vue.component('field-date-input', {
template: '<input class="form-control" v-model.lazy="displayValue" type="text">',
mixins: [VueFormGenerator.abstractField],
mounted: function () {
var self = this;
$(this.$el).daterangepicker({ autoUpdateInput: false, singleDatePicker: true }, function (start, end) {
self.displayValue = formatDate(start);
});
var startingValue = formatDate(this.displayValue);
if (startingValue !== null) {
this.displayValue = startingValue;
$(this.$el).data('daterangepicker').setStartDate(startingValue);
}
},
computed: {
displayValue: {
get: function () {
return formatDate(this.value);
},
set: function (newValue) {
$(this.$el).val(newValue);
if (this.value !== null)
$(this.$el).data('daterangepicker').setStartDate(newValue);
this.value = formatWebApiDate(newValue);
}
}
}
});
和m
之间的不替换的1
整数示例中,
n
我尝试如下使用m=10^6;
p=13^5;
n=p*(p-1)/2;
randsample
但是,我遇到了内存问题
random_indices_pairs=randsample(n,m);
有办法避免这种情况吗?这里的问题是由于 Error using zeros
Requested 1x68929060278 (513.6GB) array exceeds maximum array size preference. Creation of arrays greater than this
limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more
information.
Error in randsample (line 149)
x = zeros(1,n); % flags
很大。
答案 0 :(得分:3)
randperm
的两输入版本等效于tion
,无需替换,并且没有内存问题:
randsample
答案 1 :(得分:1)
下面的脚本应该可以满足您的需求。
m
至1
范围内的n
个随机整数。1
和n
之间找到另一个随机数%% Initialize
clearvars;
clc;
m = 10e6;
p = 13e5;
n = p*(p-1)/2;
%% Create m random integers between 1 and n
randomInt = randi(n, m, 1);
%% Find indices where duplicate random integers are
% Find indices of unique values, take the index of the first occurrence
[~, I] = unique(randomInt, 'first');
% Generate an array of all indices
dupIdx = 1:length(randomInt);
% Drop indices which point to the first occurrence of the duplicate
% This leaves indices that point to the duplicate
dupIdx(I) = [];
% Free up some memory
clear I;
if isempty(dupIdx)
disp('Done!')
else
% For those indices find another random number, not yet in randomInt
disp('Found duplicates, finding new random numbers for those')
counter = 0;
for ii = dupIdx
counter = counter + 1;
disp(strcat("Resolving duplicate ", num2str(counter), "/", num2str(length(dupIdx))))
dupe = true;
% While the replacement is already in the randomInt array, keep
% looking for a replacement
while dupe
replacement = randi(n, 1);
if ~ismember(replacement, randomInt)
% When replacement is unique in randomInt
% Put replacement in the randomInt array at the right index
randomInt(ii) = replacement;
dupe = false;
end
end
end
end
答案 2 :(得分:1)
基于评论之一(该评论还建议可能的改进)。
text/xml