How to make loop where numbers in a line of code is filled in for me?

조회 수: 2 (최근 30일)
Kristine
Kristine 2025년 9월 22일
댓글: Walter Roberson 2025년 9월 22일
How do I write a for loop for this? I want the number after station, and cast_number to be the same and looped with numbers from 1 - 24.
station01 = HB2501CTD (HB2501CTD . cast_number == 01, :);
station02 = HB2501CTD (HB2501CTD . cast_number == 02, :);
station03 = HB2501CTD (HB2501CTD . cast_number == 03, :);
station04 = HB2501CTD (HB2501CTD . cast_number == 04, :);
station05 = HB2501CTD (HB2501CTD . cast_number == 05, :);
station06 = HB2501CTD (HB2501CTD . cast_number == 06, :);
station07 = HB2501CTD (HB2501CTD . cast_number == 07, :);
station08 = HB2501CTD (HB2501CTD . cast_number == 08, :);
station09 = HB2501CTD (HB2501CTD . cast_number == 09, :);
station10 = HB2501CTD (HB2501CTD . cast_number == 10, :);
station11 = HB2501CTD (HB2501CTD . cast_number == 11, :);
station12 = HB2501CTD (HB2501CTD . cast_number == 12, :);
  댓글 수: 1
Stephen23
Stephen23 2025년 9월 22일
편집: Stephen23 2025년 9월 22일
Do not force meta-data into variable names. That is how you paint yourself into a corner.
Use arrays and indexing. Store meta-data in arrays, not in their names.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2025년 9월 22일
  댓글 수: 1
Walter Roberson
Walter Roberson 2025년 9월 22일
stations = arrayfun((CN)HB2501CTD (HB2501CTD . cast_number == CN), 1:12, 'uniform', 0);
then stations{1}, stations{2} and so on.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by