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

3 views (last 30 days)
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?

Answers (1)

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

Categories

Find more on Structures in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!