Info

この質問は閉じられています。 編集または回答するには再度開いてください。

List Variables through loop

1 回表示 (過去 30 日間)
Vyshnave Sivasankar
Vyshnave Sivasankar 2019 年 10 月 15 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I want to be able to list the values of vv when the if function does not equal 1. What am I doing wrong? Thanks!
sla=diff(idx);
for vv = 2 : length(sla)
if sla(vv)-sla(vv-1)~=1
index=vv;
end
end

回答 (1 件)

Star Strider
Star Strider 2019 年 10 月 15 日
I am not certain what you want to do.
In any event, this is likely more efficient:
idx = sort(randi(9, 1, 10));
sla = diff(idx);
index = find(diff(sla) ~= 1)
alternatively:
index = find(diff([0; sla(:)]) ~= 1)
Experiment to get the result you want.

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by