如何利用循环每次取一个数组的前几项?。

例如,A=[1:2000];如何利用循环体,循环第一次取A的前50个数,循环第二次取A的前100个数,循环第三次取A的前150个数,………………直至取完A中的数?请教大神指点。

 Akzeptierte Antwort

wakavep
wakavep am 17 Nov. 2022

0 Stimmen

AA=arrayfun(@(x) a(1:x+50),0:50:2000,'un',0)
得到的是一个cell。
利用循环:
for k=0:50:2000
AA=A(1:k+50)
end
得到的是最后一次的数。

Weitere Antworten (0)

Kategorien

Mehr zu 循环及条件语句 finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 17 Nov. 2022

Beantwortet:

am 17 Nov. 2022

Community Treasure Hunt

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

Start Hunting!