循环索引的选择

2次观看(过去30天)
Mahdi Babayi Semirmi.
Mahdi Babayi Semirmi. 2021年7月1日
你好
我有一个矢量:
v =(1:10)';
I want to have a function that can select a segment of the vector from index "a" to index "b" such that if "a" is greater than "b", it loops back on the vector and starts from the beginning, i.e., I want the function
功能Y =循环选择(V,A,B)
%%
结尾
这样
循环选择(v,7,2)
回报
[7,8,9,10,1,2]
我想知道是否有办法在不使用“如果”语句的情况下,因为它与“如果”语句相当琐碎。
谢谢你提前答案

接受答案

亚山
亚山 2021年7月1日
功能Y =循环选择(V,A,B)
n =长度(v);
IDX = A:B + N *(B
idx(idx> n)= idx(idx> n)-n;
Y = V(IDX);
结尾

更多答案(0)

下载188bet金宝搏


释放

R2021A

社区宝藏狩猎

找到Matlab Central中的宝藏,并发现社区如何帮助您!

开始狩猎!

被某某人翻译