0
votes

I have 3 different sets of data in my variable workspace with a subscript by its name for identification.

First Set in workspace:

lat1 = rand(10,1);
long1 = rand(10,1);
alt1 = rand(10,1);
time1 = rand(10,1);

Second Set in workspace:

lat2 = rand(10,1);
long2 = rand(10,1);
alt2 = rand(10,1);
time2 = rand(10,1);

Third Set in workspace:

lat3 = rand(10,1);
long3 = rand(10,1);
alt3 = rand(10,1);
time3 = rand(10,1);

Each time, manually, I enter into the code and change the subscript, such as from plot(time1,lat1) TO plot(time2, lat2). I want to plot all these data sets using a for loop (or another construct choice) without having to change the subscript each time for plotting. Something similar to below or another way to achieve the selected output:

for k = 1:3
plot(time1(k), lat(k))
plot(time1(k), long(k))
plot(time1(k), alt(k))
end
1

1 Answers

2
votes

Your question isn't very clear, so I don't fully understand what you want, but I think this might be helpful.

Can you just put them into an array and plot different columns in the array?

Something like:

lat = rand(10,3);
long = rand(10,3);
alt = rand(10,3);
time = rand(10,3);

for ii=1:3
    figure
    hold on
    plot(time(:,ii),long(:,ii),'o')
    plot(time(:,ii),alt(:,ii),'o')
    plot(time(:,ii),lat(:,ii),'o')
end

Then if you wanted to change one of the variables you just change the corresponding column. For example, if you wanted to change the equivalent of lat3, you'd just set

lat(:,3)=rand(10,1)