Array building with a for loop
I am using indexing on the right edge of a For Loop to try to build a larger 2-D array out of smaller 2-D arrays but the output of the tunnel insists on being a 3-D array. I will attach my VI. The sub VIs are not important; the comments in the block diagram should explain the situation sufficiently. Thanks!
Attachments:
Loop_array_example.vi 24 KB
Please disregard this request for help. I solved my problem by using 'insert into array' instead of building array.
Similar Messages
-
I need help with my for loop in this array
Ok well, I can't get my code to work. Also, please remember that this is just my draft so it isnt pretty. I will fix it up later so please look at it. The thing I want to do is look into the array for a time that matches what the user entered and return the toString() of that one. I know there is something wrong with my for loop but I cant figure how to fix it. please help. here is what i have so far:
import javax.swing.JOptionPane;
public class Runner
public static void main (String[] args)
String timeStr;
int time, again, optiStr;
Inbound[] in = new Inbound[25];
in[0]=new Inbound ("",0,"On Time num0");
in[1]=new Inbound ("",2,"On Time num1");
in[2]=new Inbound ("",3,"Delayed num2");
in[3]=new Inbound ("",4,"On Time");
in[4]=new Inbound ("",5,"On Time");
in[5]=new Inbound ("",6,"Canceled");
in[6]=new Inbound ("",1,"Canceled num6");
in[7]=new Inbound ("",8,"On Time");
in[8]=new Inbound ("",9,"Delayed");
in[9]=new Inbound ("",10,"On Time");
in[10]=new Inbound ("",11,"Delayed");
in[11]=new Inbound ("",12,"On Time");
in[12]=new Inbound ("",13,"Delayed");
in[13]=new Inbound ("",14,"On Time");
in[14]=new Inbound ("",15,"On Time");
in[15]=new Inbound ("",16,"On Time");
in[16]=new Inbound ("",17,"Canceled");
in[17]=new Inbound ("",18,"On Time");
in[18]=new Inbound ("",19,"On Time");
in[19]=new Inbound ("",20,"Canceled");
in[20]=new Inbound ("",21,"On Time");
in[21]=new Inbound ("",22,"Delayed");
in[22]=new Inbound ("",23,"On Time");
in[23]=new Inbound ("",24,"Cancled");
in[24]=new Inbound ("",7,"On Time num24");
do{
timeStr = JOptionPane.showInputDialog ("In military time, what hour do you want?");
time = Integer.parseInt(timeStr);
if (time<=0 || time>24)
JOptionPane.showMessageDialog (null, "Error");
optiStr = JOptionPane.showConfirmDialog (null, "If you want Incoming flights click Yes, but if not click No");
if (optiStr==JOptionPane.YES_OPTION)
//(ok this is the for loop i am talking about )
for (int index = 0; index < in.length; index++)
if ( time == Inbound.getTime())
JOptionPane.showMessageDialog (null, Inbound.tostring()); //return the time asked for
// else JOptionPane.showMessageDialog (null, "else");
}//temp return else if failed to find time asked for
// else
// if (optiStr==JOptionPane.CANCEL_OPTION)
// JOptionPane.showMessageDialog(null,"Canceled");
// else
// {Outbound.run();
// JOptionPane.showMessageDialog (null, "outbound");}//temp
again=JOptionPane.showConfirmDialog(null, "Try again?");
while (again==JOptionPane.YES_OPTION);
}any help would be greatly appriciated.rumble14 wrote:
Ok well, I can't get my code to work. Also, please remember that this is just my draft so it isnt pretty. I will fix it up later so please look at it. The thing I want to do is look into the array for a time that matches what the user entered and return the toString() of that one. I know there is something wrong with my for loop but I cant figure how to fix it. please help. here is what i have so far:
>//(ok this is the for loop i am talking about )
for (int index = 0; index < in.length; index++)
if ( time == Inbound.getTime())
JOptionPane.showMessageDialog (null, Inbound.tostring()); //return the time asked for
Inbound.getTime() is a static method of your Inbound class, that always returns the same value, I presume? As opposed to each of the 25 members of your array in, which have individual values?
Edited by: darb on Mar 26, 2008 11:12 AM -
Hi,
I'm using labVIEW V5.1
I'm trying to generate 10 1D arrays, the first array is initialized to all zeroes, then I have set up a for loop which shifts the first element by 1, then a random number is placed into the first element position. I am using a shift register to feed back in the newly generated array into the start of the loop.
By the end of the each loop I want to be able to use the array generated in an algorithm outside the loop. However I only want the Nx1 array that has just been generated.
Unfortunately, I cannot figure out how to resize, reshape or index the output array to do this.
I would like the loop to
give me out a 1D array after each iteration.
Any help would be greatly appreciated.I hope I've understood your problem.
First your vi was lacking of the sub-vi working as shift register, I've replaced it with the rotate function.
The indexing of your arrays create a 2D array whose rows are your 1D array.To pick only one of them you have to use the index array function and select which one you want.
To use your temporary data in another part of your application you should use a local variable of array2.
I did it in a separated while loop That I syncronized with the for loop using occurrence, in this way the while loop runs each time a new value is inserted in array2 (each loop of the for loop structure).
If you don't need this syncronization just get rid of occurrence functions.
I place a delay in the for loop to show what happens when running.
Hope it was helpful.
Alberto Locatelli
Attachments:
array_test_v3.vi 35 KB -
How does array obtained in a for loop?
Hi
I went previosly my question as below.
"Firstly thanks for help,
I want to obtain array from the y value calculated in the for loop .at every loop, and in same for loop these different arrays are operated.so with one for loop the calculates are obtained.
Thanks"
Now could you give me one sample program?
Thanks a lot.LabVIEW ships with a variety of examples. Search through those (hint: look under fundamentals>>arrays) to find what you are looking for.
-
Issues with nested for loops - saving images from a camera
Hi all,
I've written a vi. to capture a specific number of images ('Image No') and save these images, outputted to a folder of my choice. Each image is identified sequentially. However, I wish to do a number of iterations ('Run') of this capture sequence, such that the filename of each image would be 'Filename (Run)_(Image No).png', e.g. run 5, image 10 would be 'Filename 5_10.png'. I have tried a nested for loop for this but I receive an error 'Asynchronous I/O operation in progress' (I've attached a printscreen).
Can anyone assist me in solving this problem? I preiously posted this in machine Vision but got no response (http://forums.ni.com/t5/Machine-Vision/Capturing-image-sequences-issues-with-nested-for-loops/m-p/19...). Please find attached my vi.
Kindest regards and thanks,
Miika
Solved!
Go to Solution.
Attachments:
Labview problem.jpg 3841 KB
Image sequence save to file.vi 48 KBMiika,
the problem is not the filenam, but the name of the folder (AHHHHH!). You try to create the same folder in the outer for loop over and over again.... (it is the error message above the '======', not below )
Norbert
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it. -
Trying to save key strokes with a for loop
I have been trying to action script for years with no
success. I to some time off and learned javascript and some oop
(ruby) so I thought I would take another stab at it. I am still
having problems. Here goes...
I have several movieclips on the stage that will be set up as
buttons. They all have the same effects associated with mouseover
and mouseout so I thought I could save some key strokes with a for
loop. But I can't get it working right. Could someone tell me what
I am doing wrong please?
If anyone can help it would be appreciated.kglad,
Thanks for taking a look. In answer to your question. The
movie clip instance names are mc_ItemText0 ... mc_ItemText3.
quote:
those declarations at the top of your for-loop aren't doing
anything useful. what are the names of you movieclips that are
on-stage?
In reg\ards to the variable declarations, sorry my variable
names are causing confusion. I use the name "mc" for two different
variables. Once for the FOR loop and a separate time locally in the
functions grow and shrink. The ones set for the For loop are used
in the 'onEvents' at the bottom of the script. Sorry for the
confusion.
Because the code works if I take it out of the FOR loop and
replace the
's with the numbers that corruspond to the movie clip; I don't
think the similar names are conflicting because of the scope. To
make the code more readable and eliminate confusion I have posted
the code with unique variable names.
I have searched the forum for FOR loop difficulties and
found several cases that seemed similar to mine, but I didn't
understand what was happening.
Examples:
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=15&catid=288&threadid =1253110&highlight_key=y&keyword1=for%20loop
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=15&catid=288&threadid =1202338&highlight_key=y&keyword1=for%20loop
My code with unique variable names to end confusion: -
the demand of my application is that i can not replace for loop with a while loop.because i need fixed number of iterations and as far as i know fixed iterations could be only with possible with the for loop.
your recommended second option that i could add true/false case.
this true/false case must be inside the for loop or outside the for loop?if this case is inside the for
loop, how can i send stop command from outer while
loop?
more over do you have any example for this please?
thanks"You can execute a fixed number of iterations using a while loop by comparing the iteration count to the number of iterations you want and wiring the output of that comparison (e.g. Less Than or Equal To) to the continue (or stop) terminal of your while loop. Which comparison you use depends on personal preference, where you wire the desired count and the interation count, and whether you're using the while loop as Continue if True or Stop if True.
Ben gave you step-by-step instructions in response to your previous question. Look here for Ben's response.
Ben's response looks pretty good and detailed to me. It certa
inly deserved better than a 1-star rating. -
How to traverse an array with a for-loop in this certain way...
so I need to traverse an array starting from the first element, then from the last element, then the second element, then the second last element, then third element and so on... in a for loop
how would that look in code?
Any help would be appreciated, thanks!
Edited by: inspiredone on Apr 4, 2008 6:34 AMWow, that's a really clever and elegant way to do it promethuzz. I actually came up with something already before I read your post so yeah don't worry about me copying or anything. Mine is not as elegant/efficient and I definitely like yours a lot more but I will just share it anyway...it looks pretty similar to the second algorithm The_Matrix has provided. I figured this out from thinking how quicksort compares its pivot with the two indexes...
int front=0;
int back = a.length - 1;
int counter =0;
boolean switchflag = true;
while(front<=back)
System.out.println(a[counter]);
if(switchflag)
counter = back;
front++;
switchflag = false;
else
counter = front;
back--;
switchflag = true;
} Anyways, thanks a lot for you guys help, promethuzz, The_Matrix, and newark.
Edited by: inspiredone on Apr 4, 2008 11:25 AM
Edited by: inspiredone on Apr 4, 2008 11:27 AM -
Please help with the FOR loop and the array..
I was trying to place some words in the Movie Clip
"TextPanel" and set a
random position to each of them.
But it's not working.
1) I created a Movie Clip "word" and inside that MC I created
a text field
and gave it an identifier "textFiled".
2) The linkage name for Movie Clip "word" I set to "word".
3) In the actionscript I created an Array called "aWords".
4) Then I created a FOR loop that should
place (attach) Movie Clips "word0", "word1", "word2" and
"word3" to the
movie clip TextPanel, and set the textField text for each of
them to the
text from the Array.
But the script attaches 4 Movie Clips with a name
"Undefined", instead of 4
different names (from the Array).
What is wrong with this script?
var aWords:Array = [apple,banana,orange,mango];
for(i=0;i<aWords.length;i++){
var v = TextPanel.attachMovie("word","word"+i,i);
v.textFiled.text = aWords
v._x = randomNumber(0,Stage.width);
v._y = randomNumber(0,Stage.height);
Thanks in advanceBut in my Post I already wrote v.textFiled.text = aWords
so I don't understand what were you correcting..
And one more:
I have tested it by changing the
v.textFiled.text = aWords; to v.textFiled.text = "some
word";
and it's working fine.
So there is something wrong with the Array element, and I
don't know why..
"aniebel" <[email protected]> wrote in
message
news:ft2d5k$lld$[email protected]..
> Change:
> v.textFiled.text = aWords;
>
> to:
> v.textFiled.text = aWords
>
> It needs to know which element inside the array you want
to place in the
> textfield (or textfiled) :)
>
> If that doesn't work, double check that your instance
name is correct
> inside
> of "word".
> -
Help with a FOR loop and an object array
I need to make a for loop that takes an array of objects that contain the parameters year, type, and model (all ints) and sort by year, then divide the array in all the objects with the same year and sort them by type, then divide the array again into the objects with the same year AND type and sort them by model.
the object a Dress objects, the get methods are get+nameof parameter.
the array is a 1D array called Dresses.
I have made a paralell array to store the value of the parameters and sort that then move the array acording to that sorted array. The problem is in the division of the array.We'll give your request to do (or finish) your homework for you the attention it deserves.
-
Row operation on array with a For Loop
Hi,
I'm working with a large one dimensional column array. I'm trying to do the following
for i=1:size(A)/2
B(i,: ) =A(1+(i-1)*2:i*2)
So, for example if
A=
0
1
2
3
4
5
6
7
then
B=
0 1
2 3
4 5
6 7
My approach was to use an array subset block inside the for loop to select a number of elements but I'm not sure how to transpose the selected elements into a new row to create the new array B. Is there a more straightforward approach?
Thanks,
Mike
Solved!
Go to Solution.try experimenting with the reshape array feeding it your input array and re-sizing it to output a 2d aray. It is much faster than using a For loop becuase the data never gets moved and LV just changes the array dimensions and updates the stride.
Ben
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction -
Need help with basic "for" loops!
Here is my prompt for class:
Write a program that prompts the user to enter a sentence from the keyboard using JOptionPane.showInputDialog.
The program will print the characters back with the first letter of each word changed from lower case into upper case. If you have a capital letter in the original line and it is not the first letter of a word, then this letter should be switched from upper case to lower case. The only capital letters that should appear in the line must be the beginning letter of every word in the line. All other characters will remain the same.
I figured everything out except for one part. How do I make the first letter of each word change from lower case into uppercase? How do I switch a letter that is uppercase in the middle of a word to lowercase? Last but not least, how do I make sure that the only capital letters in the sentence are the first letter of each word?
I need to do this using for Loops, charAt(), and if/else statements because this is just an intro class. I just can't figure this last part out! Help please!String words = ...;
StringBuilder builder = new StringBuilder();
for (int i = 0; i < words.length; i++) {
char c = words.charAt(i);
boolean isUpper = Character.?(look up the methods in java.lang.Character)
boolean isLetter = ? (there are actually 2 ways to do this. Hint: you can use <= and >= and && to solve this)
if (!isLetter) {
continue;
} else {
// check if this is the start of the word. How do you know that you are at the start of a word?
if (!isUpper && isStartOfTheWord) c = Character.toUpperCase(c); //Hint: there is a way you can do this with x + y
else if (isUpper) //make c lower case
builder.append(c);
return builder.toString(); -
I get the following compiler error when using the Java 5 SE enhanced for loop with a generic collection.
Code:
public static void main(String[] args)
List<Integer> l = new ArrayList<Integer>();
l.add(new Integer(1));
printCollection(l);
private static void printCollection(Collection<?> c)
for (Object e : c)
System.out.println(e);
Error on attempting to build:
"Error: Internal compilation error, terminated with a fatal exception"
And the following from ojcInternalError.log:
java.lang.NullPointerException
at oracle.ojc.compiler.EnhancedForStatement.resolveAndCheck(Statement.java:2204)
at oracle.ojc.compiler.StatementList.resolveAndCheck(Statement.java:4476)
at oracle.ojc.compiler.MethodSymbol.resolveMethod(Symbol.java:10822)
at oracle.ojc.compiler.RawClassSymbol.resolveMethodBodies(Symbol.java:6648)
at oracle.ojc.compiler.Parser.resolveMethodBodies(Parser.java:8316)
at oracle.ojc.compiler.Parser.parse(Parser.java:7823)
at oracle.ojc.compiler.Compiler.main_internal(Compiler.java:978)
at oracle.ojc.compiler.Compiler.main(Compiler.java:745)
at oracle.jdeveloper.compiler.Ojc.translate(Ojc.java:1486)
at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.buildGraph(UnifiedBuildSystem.java:300)
at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.buildProjectFiles(UnifiedBuildSystem.java:515)
at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.buildAll(UnifiedBuildSystem.java:715)
at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.run(UnifiedBuildSystem.java:893)Install the Service Update 1 patch for JDeveloper (using the help->check for updates), and let us know if this didn't solve the problem.
-
1D Array Of String To For-Loop
Hi fellow engineers,
I'm new to LabVIEW.
I got a question,
If I got a 1D array of string and I want to loop my program to the same number of times (Iteration) in conjunction with the numbers of sub-folders generated by the "list folder" function. How can I do it?
Any help is greatly appreciated.
Solved!
Go to Solution.
Attachments:
Capture.PNG 7 KBWire the string array to the border of the for loop. LabVIEW will automatically iterate through each element of the array; you should not wire anything to the N terminal of the for loop. This is the default behavior for arrays entering a loop; if you do not want auto-indexing, right-click on the tunnel (where the array enters the loop) to change the behavior.
-
Hello,
I hope someone can point me in the right direction for my next assignment. I am very new at Java programming. For my next assignment for class I will need expand my previous program which was a mortgage calculator. The first assignment we wrote a program to show the monthly payments of a $200,000 loan at 5.75% for 30 years. Now we have to output all 360 monthly payments with pauses in between so it doesnt scoll off the page. The calculation that we use is:
month_payments = (principle * monthlyinterest) / (1-Math.pow(1 + monthlyinterest, - months));
My question is how do I get the correct calculation outputed 360 times. I would like to use the "for loop" to do this. Also what is the correct way to do the pause command? I do not want someone to write the code, I just want some help to where I need to start off, I want to learn this on my own.
Thanks in advance,
DCfor (int i ; i < 10 ; i ++ ) { System.out.println("Come sail away"); }
or;
int i = 0;
while(i < 10)
i++;
System.out.println("Come sail away");
}
Maybe you are looking for
-
Authenticating Proxy problem? Can't download TV show, view account
I'm using iTunes 8.0.1 (12) on OS X 10.5.5 on a 1GHz mini. This evening I am unable to download a TV show for which I have a season pass, nor can I view my account information. Requests like "CONNECT p8-buy.itunes.apple.com:443 HTTP/1.1" clearly get
-
No one seems to be able to help...
Ok so I have/had a droid razr, a few days ago I bent to pick my son up and my phone slipped out of the diaper bag on to the floor and the screen cracked, now nothing shows on my phone. I can see my light flashing indicating email or whatever so it's
-
Apps won't update. Help?
My Apps download, start to install and immediately stop. It then says I still need to update the apps. Any ideas? Thanks.
-
i am trying to create a drop shadow on text. i select the text and then copy and then paste in back. however, the copy shows up way above the text and not behind it. what am i doing wrong?
-
Creating ImageIcon from Image is very slow
Hi I have a program which reads a number of files which may contain (amongst other things) image data in various formats such as JPG.I read scale this down into an image object fine, and then I want to display a small version of it on screen so I put