Info

This question is closed. Reopen it to edit or answer.

How to create indexes operations?

1 view (last 30 days)
sc
sc on 9 May 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
Hi!
I've this function:
for i = 1:length(I)
ydata_low(i,:) = [I_0(i) I_1(i) I_2(i) I_3(i) I_4(i)];
ydata_high(i,:) = [I_5(i) I_6(i) I_7(i) I_8(i)];
end
where 0,1,2,3,4,5,6,7,8 are indexes. I'd like, instead this, to do that ydata_low goes from I_0(i) to I_4(i) and ydata_high goes from I_5(i) to I_b(i), where b is 8. How can I do?
  1 Comment
Dennis
Dennis on 9 May 2018
Edited: Dennis on 9 May 2018
With proper indices! Instead of using several vector I_0 to I_X better add 1 dimension to I.
ydata_low(1:5,:) = I(1:5,:);
ydata_high(1:b-5,:) = I(6:b,:);
I do not know how you populate your Is', but I suggest to do it like
for ii=1:numberofdatasets
I(ii)= %put data in here
end
Stephen Cobeldick also put together a neat post about not naming variables I_0,I_1,I_2... https://de.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval

Answers (0)

Community Treasure Hunt

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

Start Hunting!