Use for loop to assign zeros function to a variable size array

2 ビュー (過去 30 日間)
Fazlollah
Fazlollah 2024 年 3 月 21 日
回答済み: Walter Roberson 2024 年 3 月 21 日
I have the following piece of code and I would like to use a for loop to shorten it and also make it more general in case I have more that four sets of initicial conditions (IC)
Nz = 200;
number = 4;
IC_A1 = zeros (1, Nz); %for C
IC_B1 = zeros (1, Nz); %for q
IC_A2 = zeros (1, Nz); %for C
IC_B2 = zeros (1, Nz); %for q
IC_A3 = zeros (1, Nz); %for C
IC_B3 = zeros (1, Nz); %for q
IC_A4 = zeros (1, Nz); %for C
IC_B4 = zeros (1, Nz); %for q
IC = [IC_A1 IC_B1; IC_A2 IC_B2; IC_A3 IC_B3; IC_A4 IC_B4];
Do I need to use Cell array?

回答 (1 件)

Walter Roberson
Walter Roberson 2024 年 3 月 21 日
Nz = 200;
number = 4;
IC = zeros(number, Nz*2);

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by