how can I find the values 88,89,90 and replace them as 65,66,67 using a for loop?
1 次查看(过去 30 天)
显示 更早的评论
Generator = randi([65,90],[1,10])
0 个评论
回答(1 个)
Walter Roberson
2022-8-23
Generator = randi([65,90],[1,10])
for K = 1 : numel(Generator)
if Generator(K) == 88
Generator(K) = 65;
elseif Generator(K) == 89
Generator(K) = 66;
elseif Generator(K) == 90;
Generator(K) = 67;
end
end
This is deliberately clumsy -- if you have a requirement to use a for loop instead of something more efficient, then who-ever imposed the requirement to use a for loop probably wants to see the steps spelled out.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!