Replace first number of matrix with the next larger value
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jan Morawietz
am 7 Jan. 2015
Beantwortet: Azzi Abdelmalek
am 7 Jan. 2015
I have the following matrix:
StrikeMatrix11= [1:10]
Now I want to replace the first number of StrikeMatrix11 with "2" since the second number of StrikeMatrix11 is larger than its first number.
Unfortunatley, my code is a) too complex and b) not working.
Does anyone have an idea how to fix this?
if StrikeMatrix11(2)>StrikeMatrix11(1)
StrikeMatrix11(1)=StrikeMatrix11(2);
else
for n=1:10
while StrikeMatrix11(n+1)<=StrikeMatrix11(1)
StrikeMatrix11(1)=StrikeMatrix11(1);
if StrikeMatrix11(n+1)>StrikeMatrix11(1)
StrikeMatrix11(1)=StrikeMatrix11(n+1);
break
end
end
end
end
Best!
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 7 Jan. 2015
v=randi(10,1,10) % Example
idx=find(v(2:end)>v(1),1)+1
v(1)=v(idx)
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!