<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: using for loop to find minimum values and saving results in a list in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/737061#M91804</link>
    <description>&lt;P&gt;You can also use matrices + V Min() for this (remember to comment to code to make it easier to understand if needed)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

a = {2, 3, 4, 5, 6};
b = {4, 5, 7, 2, 1};
c = {9, 6, 4, 6, 2};

m = Matrix(a)` |/ Matrix(b)` |/ Matrix(c)`;
d = As List(V Min(m)`); // {2, 3, 4, 2, 1}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 21 Mar 2024 05:35:12 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2024-03-21T05:35:12Z</dc:date>
    <item>
      <title>using for loop to find minimum values and saving results in a list</title>
      <link>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/736999#M91789</link>
      <description>&lt;P&gt;I have three lists of numbers:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;a= {2,3,4,5,6}&lt;/P&gt;&lt;P&gt;b = {4,5,7,2,1}&lt;/P&gt;&lt;P&gt;c= {9,6,4,6,2}&lt;/P&gt;&lt;P&gt;I would like to take the minimum of each index from the 3 lists and turn that into a list, say d. so d = {2,3,4,2,1}.&lt;/P&gt;&lt;P&gt;the loop i have started is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;minsl = {};&lt;/P&gt;&lt;P&gt;for(i = 1, i = 6, i++,&lt;/P&gt;&lt;P&gt;mins = {a[i], b[i], c[i]};&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;minval = minimum(mins);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;minsl=insert into(minsl,minval,i);&lt;BR /&gt;If(n items(minsl)==5, break()); // this line was added to stop the loop because it gets stuck&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the output is minsl = {1,1,1,1,1} i.e. is gets stuck storing the last entry in the list only (and foes on forever without the break line), when it should be {2,3,4,2,1}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions how to fix?? Thanks!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 21:47:51 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/736999#M91789</guid>
      <dc:creator>Abby_Collins14</dc:creator>
      <dc:date>2024-03-20T21:47:51Z</dc:date>
    </item>
    <item>
      <title>Re: using for loop to find minimum values and saving results in a list</title>
      <link>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/737013#M91790</link>
      <description>&lt;P&gt;Here is how I would approach the issue&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
a = {2, 3, 4, 5, 6};
b = {4, 5, 7, 2, 1};
c = {9, 6, 4, 6, 2};

a1= sortlist(a);
remove from(a1,3,n=length(a)-2);
b1= sortlist(b);
remove from(b1,3,n=length(b)-2);
c1= sortlist(c);
remove from(c1,3,n=length(c)-2);

d=a1||b1||c1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also, please use the &amp;lt;JSL&amp;gt; icon at the top of the Preview window when entering script code.&amp;nbsp; It allows for the reader to more easily read the code.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 22:10:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/737013#M91790</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-03-20T22:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: using for loop to find minimum values and saving results in a list</title>
      <link>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/737042#M91797</link>
      <description>&lt;P&gt;thanks! this doesn't seem to preserve the order though. Essentially, I need to pull the minimum value out of the first index of the 3 lists and then store that in a list (preserving order)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;a = {2, 3, 4, 5, 6};
b = {4, 5, 7, 2, 1};
c = {9, 6, 4, 6, 2};

minsl = {};

for(i = 1, i = 5, i++,

mins = {a[i],b[i],c[i]};
minval = minimum(mins);
insert into (minsl,minval,i);
If(n items(minsl)==5, break());
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;if you run the above code ignoring the actual loop and do i=1, and then run just the inside of the loop and then put i=2 and run the inside of the loop it works (you'll see minsl = {2,3} )but for some reason the loop doesn't cycle properly and breaks&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 01:37:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/737042#M91797</guid>
      <dc:creator>Abby_Collins14</dc:creator>
      <dc:date>2024-03-21T01:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: using for loop to find minimum values and saving results in a list</title>
      <link>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/737043#M91798</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;a = {2, 3, 4, 5, 6};
b = {4, 5, 7, 2, 1};
c = {9, 6, 4, 6, 2};

minsl = {};

i = 1;

mins = {a[i],b[i],c[i]};
minval = minimum(mins);
insert into (minsl,minval,i);

i=2;

mins = {a[i],b[i],c[i]};
minval = minimum(mins);
insert into (minsl,minval,i);

i = 3;

mins = {a[i],b[i],c[i]};
minval = minimum(mins);
insert into (minsl,minval,i);

i = 4;

mins = {a[i],b[i],c[i]};
minval = minimum(mins);
insert into (minsl,minval,i);


minsl&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;i.e. the above works, but I would like to get a loop working for when I have lists of much longer lengths&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 01:48:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/737043#M91798</guid>
      <dc:creator>Abby_Collins14</dc:creator>
      <dc:date>2024-03-21T01:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: using for loop to find minimum values and saving results in a list</title>
      <link>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/737044#M91799</link>
      <description>&lt;P&gt;Your For() loop of&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For( i = 1, i = 5, i++, &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;needs to be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For( i = 1, i &amp;lt;= 5, i++, &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then it seems to work the way you want it to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here( 1 );

a = {2, 3, 4, 5, 6};
b = {4, 5, 7, 2, 1};
c = {9, 6, 4, 6, 2};

minsl = {};

For( i = 1, i &amp;lt;= 5, i++, 
	mins = a[i] || b[i] || c[i];
	minval = Minimum( mins );
	Insert Into( minsl, minval );
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Mar 2024 02:03:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/737044#M91799</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-03-21T02:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: using for loop to find minimum values and saving results in a list</title>
      <link>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/737061#M91804</link>
      <description>&lt;P&gt;You can also use matrices + V Min() for this (remember to comment to code to make it easier to understand if needed)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

a = {2, 3, 4, 5, 6};
b = {4, 5, 7, 2, 1};
c = {9, 6, 4, 6, 2};

m = Matrix(a)` |/ Matrix(b)` |/ Matrix(c)`;
d = As List(V Min(m)`); // {2, 3, 4, 2, 1}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Mar 2024 05:35:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/737061#M91804</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-03-21T05:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: using for loop to find minimum values and saving results in a list</title>
      <link>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/737199#M91820</link>
      <description>&lt;P&gt;thanks!! :)&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 13:48:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/737199#M91820</guid>
      <dc:creator>Abby_Collins14</dc:creator>
      <dc:date>2024-03-21T13:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: using for loop to find minimum values and saving results in a list</title>
      <link>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/737200#M91821</link>
      <description>&lt;P&gt;didn't think of this, good idea-thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 13:48:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/using-for-loop-to-find-minimum-values-and-saving-results-in-a/m-p/737200#M91821</guid>
      <dc:creator>Abby_Collins14</dc:creator>
      <dc:date>2024-03-21T13:48:39Z</dc:date>
    </item>
  </channel>
</rss>

