フィルターのクリア

calling matrices for a for loop

1 回表示 (過去 30 日間)
sampath kumar punna
sampath kumar punna 2019 年 10 月 26 日
コメント済み: Stephen23 2019 年 10 月 26 日
x1 =[
8 9
15 39
23 14
13 17
38 42]
x2 =[
8 9
15 39
23 14
18 2
38 42]
x3 =[
8 9
15 39
23 14
13 17
14 39]
x4 =[
8 9
15 39
23 14
18 2
13 17
38 42]
i have 4 matrices i want to call each matrix to get divided by 2
which is something like this
for i=1: 4
y(i)= x(i)/2
end
but this for loop is is not working beacuse location of x1,x2,x3,x4 is not fixed.
  1 件のコメント
Stephen23
Stephen23 2019 年 10 月 26 日
Use indexing.
Indexing is neat, simple to debug, and very effiicient (unlike what you are trying to do).

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

回答 (1 件)

David Hill
David Hill 2019 年 10 月 26 日
Why not make a cell array?
x{1}= A([1,2,3,5,8],:);
x{2}= A([1,2,3,4,8],:);
x{3}=A([1,2,3,5,7],:);
x{4}=A([1,2,3,4,5,8],:);
for i=1:4
y{i}=x{i}/2;
end

カテゴリ

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