How to Sort the Array in Min to Max in NetLogo












0















I want to sort the array in NetLogo. Like this {{array: 22 16 10 7}}



how can I achieve it?



Thanks










share|improve this question


















  • 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
















0















I want to sort the array in NetLogo. Like this {{array: 22 16 10 7}}



how can I achieve it?



Thanks










share|improve this question


















  • 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














0












0








0


1






I want to sort the array in NetLogo. Like this {{array: 22 16 10 7}}



how can I achieve it?



Thanks










share|improve this question














I want to sort the array in NetLogo. Like this {{array: 22 16 10 7}}



how can I achieve it?



Thanks







netlogo






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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














  • 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












2 Answers
2






active

oldest

votes


















1














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.)






share|improve this answer
























  • 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



















0














Did you try using sort-by? I guess that will do the magic.






share|improve this answer
























  • 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













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
});


}
});














draft saved

draft discarded


















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









1














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.)






share|improve this answer
























  • 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
















1














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.)






share|improve this answer
























  • 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














1












1








1







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.)






share|improve this answer













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.)







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 27 '18 at 17:32









Seth TisueSeth Tisue

23.5k961126




23.5k961126













  • 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











  • 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













0














Did you try using sort-by? I guess that will do the magic.






share|improve this answer
























  • 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


















0














Did you try using sort-by? I guess that will do the magic.






share|improve this answer
























  • 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
















0












0








0







Did you try using sort-by? I guess that will do the magic.






share|improve this answer













Did you try using sort-by? I guess that will do the magic.







share|improve this answer












share|improve this answer



share|improve this answer










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





















  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin