Help with Simplifying repetitive code
조회 수: 1 (최근 30일)
이전 댓글 표시
I am looking for a way to reduce writing repetative code and perhaps use for loops instead. I've been told that using eval is not the best approach when using a for loop to try and simplify the below code. Does anyone have any other suggestions/code snippets on how i can streamline this:
RD_ROI=RD(timeLimits(1):timeLimits(2));
RIC_ROI=RIC(timeLimits(1):timeLimits(2));
RLT_ROI=RLT(timeLimits(1):timeLimits(2));
ROB_ROI=ROB(timeLimits(1):timeLimits(2));
RPEC_ROI=RPEC(timeLimits(1):timeLimits(2));
RPS_ROI=RPS(timeLimits(1):timeLimits(2));
RRA_ROI=RRA(timeLimits(1):timeLimits(2));
RUT_ROI=RUT(timeLimits(1):timeLimits(2));
Basically i'm creating new variables with _ROI that take existing variable and extract a region of interest.
Thank you in advance for your time!
댓글 수: 0
답변 (1개)
Kevin Holly
2023년 1월 20일
If you have your variables as columns in a table, you could do something like this:
t=table;
t.RIC = rand(14,1);
t.RLT = rand(14,1);
t.ROB = rand(14,1);
t.RPEC = rand(14,1);
t.RPS = rand(14,1);
t.RRA = rand(14,1);
t.RUT = rand(14,1);
t
timeLimits(1) = 3;
timeLimits(2) = 10;
ROI=timeLimits(1):timeLimits(2);
t_ROI = t(ROI,:)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!