フィルターのクリア

How to plot lines for variables changing in a loop

1 回表示 (過去 30 日間)
S
S 2020 年 4 月 7 日
コメント済み: Walter Roberson 2020 年 4 月 7 日
Hi,
I have this data set. I want to make line plots for all the particle trajectories. This is the code so far.
%make structure array file
opt = {'MultipleDelimsAsOne',true};
out = {};
[fid,msg] = fopen('dataset.txt','rt');
assert(fid>=3,msg) %Throw error if condition false
while ~feof(fid) %while loop to repeat when condition is true. feof-read and display one line at a time until you reach the end of the file. ~ Logical NOT
str = fgets(fid); % read line excluding newline character
val = sscanf(str,'time%f'); % read formatted data from strings
if numel(val) %returns the number of elements in array val
hdr = regexp(fgets(fid),'\w+','match'); %returns the starting index of each substring of fgets(fid) that matches the character patterns specified by the regular expression
fmt = repmat('%f',1,numel(hdr)); %Repeat copies of array
tmp = textscan(fid,fmt,opt{:}); %Read formatted data from text file or string
tmp = cell2struct(tmp,hdr,2); %Convert cell array to structure array - structArray = cell2struct(cellArray, fields, dim)
tmp.time = val;
out{end+1} = tmp; %{end+1} assigning a value to the next position, which automatically extends the array to fit that size.
end
end
fclose(fid);
out = [out{:}]; % All structures must have the same fields!
%----------------------------------------------------------------------------------------
% Make trajectory plots.
figure; axis square; hold on;
set(gca,'XLim',[-0.02 0.02], 'YLim', [-0.02 0.02]);
numsteps=4;
for frameNr = 1:numsteps
cla;
for i=1:50
plot(out(frameNr).x(i),out(frameNr).y(i),'*');
end
%lineplot
%?
% Get the frame for the animation.
frames(frameNr) = getframe;
end
How can I plot lines for each particle trajectory here. Thank you very much.
  3 件のコメント
S
S 2020 年 4 月 7 日
Hi,
How can I add 50 animated line?
Thanks
Walter Roberson
Walter Roberson 2020 年 4 月 7 日
%initialize
for i = 1 : 50; AL(i) = animatedline(nan,nan, '-*'); end
for i=1:50
addpoints(AL(i), out(frameNr).x(i), out(frameNr).y(i));
end
drawnow()

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by