LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

MatlabScript output in loop question

Solved!
Go to solution

Hello everyone, long time reader but first time poster, and i was wondering if i could find some help in a small problem here, or... well, is more like a doubt rather than a problem.

 

I won't upload the .vi since i dont think it will be necessary, also, ignore everything else in the image (it was me just playing with image processing as i learned it), and go to where the matlab script is.

My goal, is to represent the image (taken from image data) in bits, and at the end, it has to look like... an array, 8 columns and all the rows it might need (don't have to see all the rows of course) so it will look like a matrix.

 

For example, it must look a bit like this on the user panel
|1 |0| 1| 1| 0| 1| 0| 1| (first value in 8 bits)

|1 |0| 1| 1| 1| 0| 1| 0| (second value in 8 bits)

etc...

 

So for that, i am using the de2bi matlab function, and in the output of this part is where my problem is, im putting it to take out 8 columns representing each number that comes from the image, and well, im confused about what is going out of the matlab function and the loop, as you see in the picture i uploaded, i put an indicator in the "bin" output, one automatically called Real, inside the loop, and the other Numeric, outside, also i disabled the index of the tunnel in that output. (if i enable the index, it goes out as an array)

I thought that Real and Numeric would be showing the same, but when i run it, that doesn't seem to be the case, te Real is showing the 1 and 0 (i guess it doesn't shows the 8 bits since it shows numbers but i saw in the matlab command window and there are the 8 bits being stored in "bin") and the Numeric just stays in 0, its almost as if nothing was going out of the loop, and because i am unsure of what it is dropping i really can't find a way to show the bits like in the example i said before.

 

Reading the help of de2bi, it says that its output its a matrix if the input is a vector, but i dont think it is a vector since because of the loop, it is taking value per value, so it should be going out value (in binary) per value too...

 

Thanks for the help in advance, also, if it is necessary something else to understand my problem better, please say so and i will do my best to make it easier to understand.

 

 

matlab

0 Kudos
Message 1 of 7
(3,734 Views)

Well, your FOR loop is disfunctional. Since the output tunnel is not indexing, all you get is the value from the last iteration. The loop also spins so fast that you won't see anything interesting at the "real" indicator either. You should learn about autoindexing. remove the index array and don't wire N of the FOR loop, but simply use an autoindexing input tunnel on the array. It will automatically iterate over all elements in the array, then finish the loop.

 

0 Kudos
Message 2 of 7
(3,720 Views)

@altenbach wrote:

Well, your FOR loop is disfunctional. Since the output tunnel is not indexing, all you get is the value from the last iteration. The loop also spins so fast that you won't see anything interesting at the "real" indicator either. You should learn about autoindexing. remove the index array and don't wire N of the FOR loop, but simply use an autoindexing input tunnel on the array. It will automatically iterate over all elements in the array, then finish the loop.

 


Hi, thanks a lot for the reply,

 

What you mean is to enable indexing in the tunnel right? Problem is that if i do that, the wires inside the loop, that go to the input of the matlab script, appear as broken, so i had to disable that, and use the size of the array to limit the loop iterations, technically it should stop when the array is over, so i dont think there are problems in that part.

 

Oh, and also, i dont mind if it is showing things too fast, i just wanted to make sure it is giving values, and it is giving, the problem is the output outside of the loop, that kinda think the problem is related to what you mentioned.

 

After giving a read to this http://zone.ni.com/reference/en-XX/help/371361H-01/lvhowto/auto_indexing_1/ following your recommendation, i can see that i indeed have to enable it for the output of the loop. In order to get an array with all the elements.

 

So, is like, it gets an array that has the 8 bits and it should show it in one row when it's outside of the loop, then, the loop iterates again, and it gets a new array and this time it should make it into the second row (this "matrix" appearing in the front panel) and so on, at least that is how i imagine it and how i am supposed to do it

 

I deleted everything else in the .vi and just left the matlab part so you can see for yourself that if you enable indexing at the input, it won't work (also just in case you want to try it, added a small png so you dont have to bother getting an image to try)

Download All
0 Kudos
Message 3 of 7
(3,713 Views)

Once you enable indexing, you no longer need "index array" wired to the iteration terminal or the size wired to N. Here's how i would look like. Keep it simple!

 

0 Kudos
Message 4 of 7
(3,693 Views)

Oh, i see now, it takes out each value of the array by itself and i dont have to specify so much; just fixed it, and it's pretty much doing the same it was doing before and it's a lot more simple, thanks a lot Smiley Surprised.


Would put that as solution but this still kinda takes me back to the same question i had in the beginning, i can't see the values that the loop is giving with the array indicator right?; at least, when i try it just stays grayed out.

 

And i can't find any tool in the array palletes that could show me the 8 bits of each iteration divided by row that is what i kind of want to display in the front panel... 

And thanks again, we have to learn labview pretty much by ourselves so being pointed things like what you just told me is pretty interesting; is a bit harder to see than all signal processing related stuff, but the digital side is pretty awesome.

Also, just noticed that you pretty much told me everything from the beginning, what you just showed me in the pic., but i think i missread it haha, i thought you just wanted me to take out the array lenght one connected at the N. Just wanted to say sorry for that and thanks.

0 Kudos
Message 5 of 7
(3,677 Views)
Solution
Accepted by topic author J.Rodriguez

I don't know why you are so fixated on matlab, because LabVIEW can do all this much simpler directly. here's one possible solution. (LabVIEW 8.5. For other possible outputs you could reverse the boolean array, so modify as needed.).

 

 

(Your main mistake with matlab is that your matlab output is defined as a scalar, while it should be a vector. Your output tunnel of the matlab node has the wrong data type.)

 

 

Download All
Message 6 of 7
(3,650 Views)

Oh, thanks a lot, yes, i was almost 100% sure that my problem was related to that part; what i really lack is experience in working with labview as far as i can see.

And as all programming i imagined there was another way, this was kinda like the only way i found out (after a lot of work) and tried my best to get into it (because i have a date set to show this, i thought i didn't have time to find other way)

 

Thank you very much for all the support, i really want to learn to do more things with labview, really awesome tool ever since doing TDM with it and sending things over the network, will be doing my best to be able to give advices like you do as well.

Thanks again!

0 Kudos
Message 7 of 7
(3,642 Views)