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

2 visualizzazioni (ultimi 30 giorni)
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?

Risposte (1)

Walter Roberson
Walter Roberson il 21 Mar 2024
Nz = 200;
number = 4;
IC = zeros(number, Nz*2);

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by