how to create a for loop 380:780?

조회 수: 1 (최근 30일)
vicsm
vicsm 2019년 9월 13일
댓글: vicsm 2019년 9월 13일
Hi,
how can I create a for loop between in this statement
CM4_380 = spec_data(spec_data.wavelength>380 & spec_data.wavelength<381,:);
so it for loops between 380:780? Basically, to make this:
CM4_381 = spec_data(spec_data.wavelength>381 & spec_data.wavelength<382,:);
CM4_382 = spec_data(spec_data.wavelength>382 & spec_data.wavelength<383,:);
CM4_383 = spec_data(spec_data.wavelength>383 & spec_data.wavelength<384,:);
etc. Plus I need to save each of those tables.
Thank you for your help!

채택된 답변

the cyclist
the cyclist 2019년 9월 13일
I would use a cell array, not variable names that also encode an index:
for ic = 380:780
CM4{ic} = spec_data(spec_data.wavelength>ic & spec_data.wavelength<(ic+1),:);
end
  댓글 수: 10
Walter Roberson
Walter Roberson 2019년 9월 13일
I would suggest
for ic = 380:780
CM4{ic-380+1} = spec_data(spec_data.wavelength>ic & spec_data.wavelength<(ic+1),:);
end
unless you have a use for CM4{1} to CM4{379}
vicsm
vicsm 2019년 9월 13일
I does work, thank you!

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

추가 답변 (0개)

카테고리

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