Current location - Training Enrollment Network - Mathematics courses - Mathematical experiment MATLAB
Mathematical experiment MATLAB
How to find the number of zeros and 1 in an array with any given length by matlab?

This problem can be solved by the following steps:

1, according to the meaning of the question, create a custom function, such as mffunc (x).

2. Use the find () function and the length () function to find 0 and 1. that is

N = length (find(X==0))

M = length (find(X== 1))

3. Use the fprintf () output function to output the numbers 0 and 1, that is

Fprintf (number of' 0% d \ n', n);

FPRINTF (number of'1%d \ n', m)

4. Use the window command to find the number of 0 and 1 in the array, that is

a =;

mfunc(A)

Step 5 get the results