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!