Writing complex term in matlab in simple way
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Jimmy cho
am 25 Dez. 2020
Beantwortet: Walter Roberson
am 25 Dez. 2020
Hi guys,
Im trying to do the same concept of what my code below does, but in a simple approach with different way.
my code in matlab is:
y=[1 -1 1 -1 -1 3 -4 5 -5]; %an array of integer values
output=+(y>0); %output result
So I want to do the same concept of what my code above does but simple approach/way in matlab like using for loop or whatever simple way(exactly the term +(y>0) is a complex term and need it to be more simplified with simple code row in matlab)
Could anyone please help me out on this? appreciated!
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 25 Dez. 2020
output = zeros(size(y)) ;
for K=1:numel(y)
if y(K) > 0
output(K) = 1;
end
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!