How to Sort the Array in Min to Max in NetLogo
I want to sort the array in NetLogo. Like this {{array: 22 16 10 7}}
how can I achieve it?
Thanks
netlogo
add a comment |
I want to sort the array in NetLogo. Like this {{array: 22 16 10 7}}
how can I achieve it?
Thanks
netlogo
1
Hi Osama, in order to get a more accurate answer from the community, it would be a good idea to include your current code (what you have tried so far).
– ch_mike
Nov 23 '18 at 22:35
add a comment |
I want to sort the array in NetLogo. Like this {{array: 22 16 10 7}}
how can I achieve it?
Thanks
netlogo
I want to sort the array in NetLogo. Like this {{array: 22 16 10 7}}
how can I achieve it?
Thanks
netlogo
netlogo
asked Nov 23 '18 at 21:24
Osama UsmaniOsama Usmani
81
81
1
Hi Osama, in order to get a more accurate answer from the community, it would be a good idea to include your current code (what you have tried so far).
– ch_mike
Nov 23 '18 at 22:35
add a comment |
1
Hi Osama, in order to get a more accurate answer from the community, it would be a good idea to include your current code (what you have tried so far).
– ch_mike
Nov 23 '18 at 22:35
1
1
Hi Osama, in order to get a more accurate answer from the community, it would be a good idea to include your current code (what you have tried so far).
– ch_mike
Nov 23 '18 at 22:35
Hi Osama, in order to get a more accurate answer from the community, it would be a good idea to include your current code (what you have tried so far).
– ch_mike
Nov 23 '18 at 22:35
add a comment |
2 Answers
2
active
oldest
votes
The array extension doesn't provide for sorting.
Consider using a list instead. Normally in NetLogo we use lists and agentsets for everything; using arrays at all is rare.
But, assuming you really need a sorted array, you could copy the array to a list, sort the list, then make a new array from the result. (Or store the sorted items back into the original array, one at a time.)
Hi, How can I generate a list of random values like "set severityLevel random 3" I want a list of random values of severityLevel
– Osama Usmani
Dec 4 '18 at 11:05
To ask something new, please open a new question.
– Seth Tisue
Dec 4 '18 at 19:55
add a comment |
Did you try using sort-by? I guess that will do the magic.
yes i did by got this error SORT-BY expected input to be a list or agentset but got the org.nlogo.extensions.array.ArrayExtension$LogoArray {{array: 16 34 16 25}} instead.
– Osama Usmani
Nov 23 '18 at 21:36
How did you create your array? You should be able to use 'sort [22 16 10 7]'
– HappyR
Nov 23 '18 at 21:44
my array is created by using this command array:set tempArray resource_id round (sqrt(( xcor - xloc ) ^ 2 + (ycor - yloc) ^ 2 ))
– Osama Usmani
Nov 23 '18 at 21:53
1
@HappyR that's a list, not an array. normally in NetLogo we use lists for everything, using an array instead is unusual
– Seth Tisue
Nov 27 '18 at 17:29
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453084%2fhow-to-sort-the-array-in-min-to-max-in-netlogo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The array extension doesn't provide for sorting.
Consider using a list instead. Normally in NetLogo we use lists and agentsets for everything; using arrays at all is rare.
But, assuming you really need a sorted array, you could copy the array to a list, sort the list, then make a new array from the result. (Or store the sorted items back into the original array, one at a time.)
Hi, How can I generate a list of random values like "set severityLevel random 3" I want a list of random values of severityLevel
– Osama Usmani
Dec 4 '18 at 11:05
To ask something new, please open a new question.
– Seth Tisue
Dec 4 '18 at 19:55
add a comment |
The array extension doesn't provide for sorting.
Consider using a list instead. Normally in NetLogo we use lists and agentsets for everything; using arrays at all is rare.
But, assuming you really need a sorted array, you could copy the array to a list, sort the list, then make a new array from the result. (Or store the sorted items back into the original array, one at a time.)
Hi, How can I generate a list of random values like "set severityLevel random 3" I want a list of random values of severityLevel
– Osama Usmani
Dec 4 '18 at 11:05
To ask something new, please open a new question.
– Seth Tisue
Dec 4 '18 at 19:55
add a comment |
The array extension doesn't provide for sorting.
Consider using a list instead. Normally in NetLogo we use lists and agentsets for everything; using arrays at all is rare.
But, assuming you really need a sorted array, you could copy the array to a list, sort the list, then make a new array from the result. (Or store the sorted items back into the original array, one at a time.)
The array extension doesn't provide for sorting.
Consider using a list instead. Normally in NetLogo we use lists and agentsets for everything; using arrays at all is rare.
But, assuming you really need a sorted array, you could copy the array to a list, sort the list, then make a new array from the result. (Or store the sorted items back into the original array, one at a time.)
answered Nov 27 '18 at 17:32
Seth TisueSeth Tisue
23.2k960125
23.2k960125
Hi, How can I generate a list of random values like "set severityLevel random 3" I want a list of random values of severityLevel
– Osama Usmani
Dec 4 '18 at 11:05
To ask something new, please open a new question.
– Seth Tisue
Dec 4 '18 at 19:55
add a comment |
Hi, How can I generate a list of random values like "set severityLevel random 3" I want a list of random values of severityLevel
– Osama Usmani
Dec 4 '18 at 11:05
To ask something new, please open a new question.
– Seth Tisue
Dec 4 '18 at 19:55
Hi, How can I generate a list of random values like "set severityLevel random 3" I want a list of random values of severityLevel
– Osama Usmani
Dec 4 '18 at 11:05
Hi, How can I generate a list of random values like "set severityLevel random 3" I want a list of random values of severityLevel
– Osama Usmani
Dec 4 '18 at 11:05
To ask something new, please open a new question.
– Seth Tisue
Dec 4 '18 at 19:55
To ask something new, please open a new question.
– Seth Tisue
Dec 4 '18 at 19:55
add a comment |
Did you try using sort-by? I guess that will do the magic.
yes i did by got this error SORT-BY expected input to be a list or agentset but got the org.nlogo.extensions.array.ArrayExtension$LogoArray {{array: 16 34 16 25}} instead.
– Osama Usmani
Nov 23 '18 at 21:36
How did you create your array? You should be able to use 'sort [22 16 10 7]'
– HappyR
Nov 23 '18 at 21:44
my array is created by using this command array:set tempArray resource_id round (sqrt(( xcor - xloc ) ^ 2 + (ycor - yloc) ^ 2 ))
– Osama Usmani
Nov 23 '18 at 21:53
1
@HappyR that's a list, not an array. normally in NetLogo we use lists for everything, using an array instead is unusual
– Seth Tisue
Nov 27 '18 at 17:29
add a comment |
Did you try using sort-by? I guess that will do the magic.
yes i did by got this error SORT-BY expected input to be a list or agentset but got the org.nlogo.extensions.array.ArrayExtension$LogoArray {{array: 16 34 16 25}} instead.
– Osama Usmani
Nov 23 '18 at 21:36
How did you create your array? You should be able to use 'sort [22 16 10 7]'
– HappyR
Nov 23 '18 at 21:44
my array is created by using this command array:set tempArray resource_id round (sqrt(( xcor - xloc ) ^ 2 + (ycor - yloc) ^ 2 ))
– Osama Usmani
Nov 23 '18 at 21:53
1
@HappyR that's a list, not an array. normally in NetLogo we use lists for everything, using an array instead is unusual
– Seth Tisue
Nov 27 '18 at 17:29
add a comment |
Did you try using sort-by? I guess that will do the magic.
Did you try using sort-by? I guess that will do the magic.
answered Nov 23 '18 at 21:33
HappyRHappyR
138
138
yes i did by got this error SORT-BY expected input to be a list or agentset but got the org.nlogo.extensions.array.ArrayExtension$LogoArray {{array: 16 34 16 25}} instead.
– Osama Usmani
Nov 23 '18 at 21:36
How did you create your array? You should be able to use 'sort [22 16 10 7]'
– HappyR
Nov 23 '18 at 21:44
my array is created by using this command array:set tempArray resource_id round (sqrt(( xcor - xloc ) ^ 2 + (ycor - yloc) ^ 2 ))
– Osama Usmani
Nov 23 '18 at 21:53
1
@HappyR that's a list, not an array. normally in NetLogo we use lists for everything, using an array instead is unusual
– Seth Tisue
Nov 27 '18 at 17:29
add a comment |
yes i did by got this error SORT-BY expected input to be a list or agentset but got the org.nlogo.extensions.array.ArrayExtension$LogoArray {{array: 16 34 16 25}} instead.
– Osama Usmani
Nov 23 '18 at 21:36
How did you create your array? You should be able to use 'sort [22 16 10 7]'
– HappyR
Nov 23 '18 at 21:44
my array is created by using this command array:set tempArray resource_id round (sqrt(( xcor - xloc ) ^ 2 + (ycor - yloc) ^ 2 ))
– Osama Usmani
Nov 23 '18 at 21:53
1
@HappyR that's a list, not an array. normally in NetLogo we use lists for everything, using an array instead is unusual
– Seth Tisue
Nov 27 '18 at 17:29
yes i did by got this error SORT-BY expected input to be a list or agentset but got the org.nlogo.extensions.array.ArrayExtension$LogoArray {{array: 16 34 16 25}} instead.
– Osama Usmani
Nov 23 '18 at 21:36
yes i did by got this error SORT-BY expected input to be a list or agentset but got the org.nlogo.extensions.array.ArrayExtension$LogoArray {{array: 16 34 16 25}} instead.
– Osama Usmani
Nov 23 '18 at 21:36
How did you create your array? You should be able to use 'sort [22 16 10 7]'
– HappyR
Nov 23 '18 at 21:44
How did you create your array? You should be able to use 'sort [22 16 10 7]'
– HappyR
Nov 23 '18 at 21:44
my array is created by using this command array:set tempArray resource_id round (sqrt(( xcor - xloc ) ^ 2 + (ycor - yloc) ^ 2 ))
– Osama Usmani
Nov 23 '18 at 21:53
my array is created by using this command array:set tempArray resource_id round (sqrt(( xcor - xloc ) ^ 2 + (ycor - yloc) ^ 2 ))
– Osama Usmani
Nov 23 '18 at 21:53
1
1
@HappyR that's a list, not an array. normally in NetLogo we use lists for everything, using an array instead is unusual
– Seth Tisue
Nov 27 '18 at 17:29
@HappyR that's a list, not an array. normally in NetLogo we use lists for everything, using an array instead is unusual
– Seth Tisue
Nov 27 '18 at 17:29
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453084%2fhow-to-sort-the-array-in-min-to-max-in-netlogo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Hi Osama, in order to get a more accurate answer from the community, it would be a good idea to include your current code (what you have tried so far).
– ch_mike
Nov 23 '18 at 22:35