replace element in the vector without using loops or if statement
Ältere Kommentare anzeigen
using a logical vector and 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 the input is a row vector.)
here is the given code:
function [ y ] = nottwo( v )
y = [];
for i = 1:length(v)
if v(i)~= 2
y = [y, 0];
else
y = [y, 10];
end
end
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!