From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

2D array with ones and zeros

Solved!
Go to solution

Hi,

i want to use a MATLAB code in Labview, but without using MATLAB.

The code is the following:

 

Mask = ones(size(cc));
Mask(1:sze,:) = 0;
Mask(:,1:sze) = 0;
Mask(end-sze+1:end,:) = 0;
Mask(:,end-sze+1:end) = 0;

 

It should be a 2D array with ones and boarders with zeros. The width of the boarders are sze and the 2D array has the size of cc.

I can create an array of zeros but that's all.

Has anybody an idea how to realize it without using for-loops?

 

thanks....

0 Kudos
Message 1 of 5
(5,399 Views)

If you want the elements to be different, no you have to use loops. The good news though is that if all the inputs to the loop comes from constants LV will generate the array at edit time and store the result in the VI as though it were a constant.

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 5
(5,395 Views)

I attach one possible solution.

You con refine it by adding:

1) Adjust the Vi such that they work as most of the array functions. This is, if you wire "rows" the column value is disabled; if you wire "cols" the row value is disabled. For simplicity I used a boolean flag.

2) Note that the array of zeros to be replaced is created with dimensions <sze x length(cc)>. Thus when replacing columns it needs to be transposed.

3) Make a input sanitation to avoid nonsquare matrices and other funny stuff.

 

Regards

Download All
0 Kudos
Message 3 of 5
(5,388 Views)
Solution
Accepted by topic author gruenschnabel

@gruenschnabel wrote:

It should be a 2D array with ones and boarders with zeros. The width of the boarders are sze and the 2D array has the size of cc.

I can create an array of zeros but that's all.


Here's what I would do:

 

 

(Attached is a LabVIEW 8.2 version of the code) 


@gruenschnabel wrote:

Has anybody an idea how to realize it without using for-loops?


What's wrong with FOR loops? Why such an arbitrary restrictions?

(Unless you are on FPGA, things need to loop no matter what, even it it is hidden inside functions). 😄

 

(See also this discussion)

 

 

Download All
Message 4 of 5
(5,381 Views)

hi,

thanks for the fast responses.i could implement the code successfully 🙂

 

0 Kudos
Message 5 of 5
(5,339 Views)