plotting multiple series on one graph from a text file
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Star Strider
2019-2-11
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 个评论
Star Strider
2019-2-23
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:
%20-%202019%2002%2023.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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!