Help with Simplifying repetitive code
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Kevin Holly
am 20 Jan. 2023
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 Kommentare
Siehe auch
Kategorien
Mehr zu Desktop finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!