ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How create Local Variable

I need a code Matlab in code LabView. The code Matlab is this:

 

k = 1;
for i = 1:m
    for j = 1:n
        if(imageGray(i,j)==255)
            Vec1(k,:) = [i j];
            k = k + 1;
        end
    end
end

 

For this i need create a local variable "k" andI do not know. Help me please.

0 Kudos
Message 1 of 11
(4,741 Views)

In LabVIEW the wire is the variable.

It looks like you want to build a 1D array (Vec1) with all values of an array  (Gray) which are 255.

 

(note all values in the output array are 255, so the code could be a lot simpler. do an =255 on the array, count the numbers of true and build a new array.

 

 

Ton

 

Message Edited by TonP on 09-02-2008 06:48 PM
Message Edited by TonP on 09-02-2008 06:50 PM
Message Edited by TonP on 09-02-2008 06:50 PM
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 2 of 11
(4,737 Views)
so so, i need to build a 2D(Vec1) array with the position in the image array of all values of this array wich are 255.
0 Kudos
Message 3 of 11
(4,728 Views)

Hi Chilywiliyx,

 

Firstly, in order to look at image attributes, unless you are importing the picture as an array you will need the NI-Vision module. If you are importing the picture as a 2D array, then you can create a 2D array on the front panel. Your nested for loops can be converted to nested for loops in LabView and your if condition is a case structure. I hope that answers your question?

 

Ipshita C.

National Instruments
Applications Engineer
Message 4 of 11
(4,675 Views)

chiliwilyx wrote:
so so, i need to build a 2D(Vec1) array with the position in the image array of all values of this array wich are 255.

OK, you need to tell us more about the desired 2D array output.

 

  • Is it a 2xN array, where each column is a pair of coordinates pointing to the 255 values in the input?
  • Is it e.g. a 2D boolean array of the same size as the input array, with all positions TRUE corrsponding the the 255 locations?
  • ...?

 

Also remember that in LabVIEW the array indices start with zero, while in matlab they start with one.

 

Lets assume you have the following 2D array input:

 

255 126 245 053

234 255 255 110

255 080 048 255

102 002 255 255

 

What should the desired output array look like?

 

 

Message 5 of 11
(4,669 Views)

For this matrix... 

 

255 126 245 053

234 255 255 110

255 080 048 255

102 002 255 255

 

the desired output array is...

 

0 0 

1 1

1 2

2 0 

2 3

3 2

3 3

 

you understand me? 

 

 

0 Kudos
Message 6 of 11
(4,635 Views)

It looks like you want to search a 2D array for a specified value and return the locations of where this value appears. Try using the attached VI. It was written in LV 8.2.

 

 

0 Kudos
Message 7 of 11
(4,628 Views)

Here's a quick draft. One loop ought to be enough! 😉

 

 

Message Edited by altenbach on 09-04-2008 01:05 PM
Download All
Message 8 of 11
(4,612 Views)

yes you are right but this example to searh only one location of a row, for exmple you have this matrix...

 

255 255   1

 2    255   0

 0    255 255

 

The out is ...

 

0 0

1 2

2 1

 

and the out desirable is...

 

0 0

0 1 

1 2

2 1

2 2 

 

 

0 Kudos
Message 9 of 11
(4,610 Views)

Do you want the VI to find all occurances of 255 or just the first occurance of 255 on each row?

 

edit: You're right my VI doesnt work correctlySmiley Sad. Just use the one that was posted after mine.

Message Edited by sgregor249 on 09-04-2008 03:16 PM
0 Kudos
Message 10 of 11
(4,598 Views)