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 CenterFile Exchange에서 Loops 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