plotting multiple series on one graph from a text file

4 visualizaciones (últimos 30 días)
ciaran balfe
ciaran balfe el 11 de Feb. de 2019
Comentada: ciaran balfe el 11 de Mzo. de 2019
i am trying to make a single graph from a text file which is looped with 15 different variables over time.
does anyone know how i can do this? below is an attachment of the text file im attempting to graph.
column one repeats itself 1-15 and i wish for each integer from 1-15 to have its own series on the graph

Respuesta aceptada

Star Strider
Star Strider el 11 de Feb. de 2019
They all appear to plot together, and there is no easy way to offset them to plot them in a single plot. The best option then appears to be plotting them each in a subplot:
fidi = fopen('carpos.txt','rt');
Dc = textscan(fidi, '%f%f%f', 'CollectOutput',1);
D = cell2mat(Dc);
endData = find(D(:,1) == 14, 1, 'last');
D = D(1:endData,:);
Dr = reshape(D, 15, 3, []);
figure
for k1 = 1:size(Dr,1)
subplot(5,3,k1)
plot3(squeeze(Dr(k1,1,:)), squeeze(Dr(k1,2,:)), squeeze(Dr(k1,3,:)))
grid on
axis equal
title(sprintf('%d',k1-1))
end
Experiment to get the result you want.
  7 comentarios
Star Strider
Star Strider el 23 de Feb. de 2019
You need to tell textscan to ignore the column (since I believe that is what you want to do). Do that by adding a ‘%*f’ to the end of the format string:
fidi = fopen('pos2.txt');
Dc = textscan(fidi, '%f%f%f%*f', 'CollectOutput',1);
fclose(fidi);
D = cell2mat(Dc);
ExptVct = unique(D(:,1)); % ‘Experiments’ Vector (Assumes All Data Sets Have The Same Number Of Experiments)
RowLim = floor(size(D,1)/numel(ExptVct))*numel(ExptVct); % Row Limit Of Data Sets With Complete Experiments
D = D(1:RowLim,:); % Trim ‘D’ To Data Sets With Complete Experiments
Dr = reshape(D, numel(ExptVct), [], 3);
figure
hold all
for k1 = 1:size(Dr,1)
plot(squeeze(Dr(k1,:,2)), squeeze(Dr(k1,:,3)))
end
hold off
grid
xlabel('Simulation Time (10^{-1} s)')
title('Car Position')
legend(compose('%2d',ExptVct), 'Location','NW')
producing:
plotting multiple series on one graph from a text file - (2019 02 11-13) - 2019 02 23.png
This looks like the previous plots, so I’m guessing that I ignored the correct () column of repeated ‘2’ values.
Experiment to get the result you want.
ciaran balfe
ciaran balfe el 11 de Mzo. de 2019
hi thank you again for your help, i hope you dont mind me asking another question. i have 2 output files and the are crossing over in data. i basically am looking for the exact same graph as you have kindly shown me beofre but it isnt graphing properly. ive attached a text file im trying to graph. thank you again. (fyi you were completely correct about ignoring the 4th column, its to be ignored in this one too).

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Annotations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by