determine the loop which satisfies the particular condition.

2 ビュー (過去 30 日間)
sermet
sermet 2014 年 5 月 17 日
コメント済み: sermet 2014 年 5 月 17 日
A=[1 1;2 2;3 3;4 4;5 5;6 6;7 7;8 8;9 9;10 10;11 11;12 12;13 13]
B=[3;4;3;3]
%I need to create this loop w.r.t A and B.
x1=A(1:B(1),:)
x2=A(B(1)+1:B(1)+B(2),:)
x3=A(B(1)+B(2)+1:B(1)+B(2)+B(3),:)
x4=A(B(1)+B(2)+B(3)+1:B(1)+B(2)+B(3)+B(4),:)

採用された回答

Image Analyst
Image Analyst 2014 年 5 月 17 日
I hope this wasn't your homework (taking you at your word since you did not tag it as homework) because it looks like it.
clc;
workspace;
A=[1 1;2 2;3 3;4 4;5 5;6 6;7 7;8 8;9 9;10 10;11 11;12 12;13 13]
B=[3;4;3;3]
% I need to create this loop w.r.t A and B.
x1=A(1:B(1),:)
x2=A(B(1)+1:B(1)+B(2),:)
x3=A(B(1)+B(2)+1:B(1)+B(2)+B(3),:)
x4=A(B(1)+B(2)+B(3)+1:B(1)+B(2)+B(3)+B(4),:)
for k = 1 : length(B)
if k == 1
row1 = 1
else
row1 = 1 + sum(B(1:k-1))
end
row2 = sum(B(1:k))
x{k} = A(row1:row2, :)
end
% Display in command window.
celldisp(x);
  1 件のコメント
sermet
sermet 2014 年 5 月 17 日
no it doesn't my homework

サインインしてコメントする。

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2014 年 5 月 17 日
x = mat2cell(A,B,size(A,2))

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by