Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I don\'t want to see C language. I want Matlab code! please!! Write the function

ID: 3528702 • Letter: I

Question

I don't want to see C language. I want Matlab code! please!! Write the function convert_to_numbers() that takes in an array of Booleans and returns an array of the numbers that correspond to the indices that are associated with true values. Examples: a = [ true, false, true, false ]; % the 1st and 3rd locations are true, so returns [1, 3] convert_to_numbers( a ) ans = 1 3 a = [ false, false, false, true, true, true ]; convert_to_numbers( a ) % 4th, 5th, and 6th locations are true, so returns [4, 5, 6] ans = 4 5 6 a = [ false, false, false ]; convert_to_numbers( a ) % No values are true, thus the empty array is returned. ans = []

Explanation / Answer

function [truths]=convert_to_numbers(bools)

truths=[]; %empty array

for i=1:length(bools)

if(bools(i)==true)

truths(length(truths)+1)=i;

end

end