function [ c ] = countA( v ) c = 0;
for i = 1:length(v)
if v(i) < 4 c = c+1;
end end
end
Write a function countB which has the same behavior using a single line of code (3 total lines if you count the “function” line and the “end” line). Your function should not have any loops or if statements in it. You should assume v is a row vector. (Hint. Use a logical vector.)
function [ c ] = countB( v ) ???
end
Matlab code:
function [c] = countB(v)
c = sum(v(:) < 4);
end
Get Answers For Free
Most questions answered within 1 hours.