From: Anamika on
Hello,

How do you refer to the elements of an array that you load in a for loop?

In the code below, for the subplot section how can the variable be set so that it changes every time from X1 to X2 and so on until the loop gets over.

Thanks for your input!
~Mika

% Data file containing coordinates to be plotted

load MyDataSet.dat

% Loaded data gets assigned

X1 = MyDataSet(1:616,2); Y1 = MyDataSet(1:616, 3);
X2 = MyDataSet(617:1131,2); Y2 = MyDataSet(617:1131, 3);
X3 = MyDataSet(1132:1655,2); Y3 = MyDataSet(1132:1655, 3);
X4 = MyDataSet(1656:2050,2); Y4 = MyDataSet(1656:2050, 3);
.....
.....
.....
X20 = MyDataSet(6661:6900,2); Y20 = MyDataSet(6661:6900, 3);

% Sublot routine
for n=1:20
h(n)=subplot(20,1,n);
plot(X1,Y1, 'r'); % HOW TO REFER ARRAY ELEMENTS HERE?
hold on;
end