How to plot x-z plot which is varying in time (a dynamic plot)?

2 次查看(过去 30 天)
I have my data (attached here), with col1: ion number, col2:x position, col3: yposition, col4: z position, col5: time, col6: temperature. I want to plot x-z (then later y z and temperature,z etc separately) which is varing in time according to column 4. The data points need to be dark colored dots to have a better view as if it looks like particles moving with time when I playthe time bar. As the x, y and z recorded each 500 microseconds every time, is it possible to plot with ta time bar so that I can drag the bar and show at each time what exactly the value of x and z? Can anyone help me to make a code for this? I dont have additional toolboxes! hope I can make with basic matlab codes.

采纳的回答

Voss
Voss 2022-11-10
编辑:Voss 2022-11-14
Something like this might be a start, if I understand what you want to do:
function ionGUI()
t = readtable('SampleData.txt');
[time,~,jj] = unique(t.time);
f = figure();
ax = [];
ax(end+1) = subplot(3,1,1);
title('x-z');
ax(end+1) = subplot(3,1,2);
title('y-z');
ax(end+1) = subplot(3,1,3);
title('temp-z');
ion_line = [ ...
line( ...
'Parent',ax(1), ...
'LineStyle','none', ...
'Marker','.', ...
'XData',[], ...
'YData',[]);
line( ...
'Parent',ax(2), ...
'LineStyle','none', ...
'Marker','.', ...
'XData',[], ...
'YData',[]);
line( ...
'Parent',ax(3), ...
'LineStyle','none', ...
'Marker','.', ...
'XData',[], ...
'YData',[]) ...
];
slider = uicontrol( ...
'Parent',f, ...
'Style','slider', ...
'Units','normalized', ...
'Position',[0.05 0 0.9 0.05], ...
'Value',0, ...
'SliderStep',[1 10]/(numel(time)-1), ...
'Callback',@cb_slider);
cb_slider(slider);
function cb_slider(src,~)
idx = 1+round(get(src,'Value')*(numel(time)-1));
z = t{jj == idx,'z'};
set(ion_line(1),'XData',z,'YData',t{jj == idx,'x'});
set(ion_line(2),'XData',z,'YData',t{jj == idx,'y'});
set(ion_line(3),'XData',z,'YData',t{jj == idx,'temperature'});
end
end
Alternatively, you might look into using animated lines.
  4 个评论
aneps
aneps 2022-11-14
Another attempt I made was to use this function in a different script with for loop plotting as follows, still no success :(
mlist =[354.19 645.33 768.9] ;
col = ['b' 'm' 'g'];
t1 = readtable('SampleData.txt');
for k = 1:size(mlist,2)
m = mlist(1,k);
rows = (t1.mass == m);
t =t1(rows,:);
c=col(1,k);
ionGUI(t,c)
hold on
end
hold off
Here I m calling the function separately for each mass and plottng on the same figure... I am not getting why this is not working!
Voss
Voss 2022-11-14
编辑:Voss 2022-11-14
Maybe something like this:
function ionGUI()
t = readtable('SampleData.txt');
[mass,~,kk] = unique(t.mass);
[time,~,jj] = unique(t.time);
NM = numel(mass);
NT = numel(time);
f = figure();
ax = [];
ax(end+1) = subplot(3,1,1);
title('x-z');
ax(end+1) = subplot(3,1,2);
title('y-z');
ax(end+1) = subplot(3,1,3);
title('temp-z');
colors = get(ax(1),'ColorOrder');
NC = size(colors,1);
colors = repmat(colors,ceil(NM/NC),1);
ion_line = zeros(NM,3);
for m = 1:NM
for aa = 1:3
ion_line(m,aa) = line( ...
'Parent',ax(aa), ...
'LineStyle','none', ...
'Marker','.', ...
'MarkerEdgeColor',colors(m,:), ...
'MarkerFaceColor',colors(m,:), ...
'XData',[], ...
'YData',[]);
end
end
slider = uicontrol( ...
'Parent',f, ...
'Style','slider', ...
'Units','normalized', ...
'Position',[0.05 0 0.9 0.025], ...
'Value',0, ...
'SliderStep',[1 10]/(NT-1), ...
'Callback',@cb_slider);
t_obj = uicontrol( ...
'Parent',f, ...
'Style','text', ...
'Units','normalized', ...
'Position',[0.4 0.025 0.2 0.04], ...
'String','');
cb_slider(slider);
function cb_slider(src,~)
t_idx = 1+round(get(src,'Value')*(NT-1));
for mm = 1:NM
idx = jj == t_idx & kk == mm;
z = t{idx,'z'};
set(ion_line(mm,1),'XData',z,'YData',t{idx,'x'});
set(ion_line(mm,2),'XData',z,'YData',t{idx,'y'});
set(ion_line(mm,3),'XData',z,'YData',t{idx,'temperature'});
end
set(t_obj,'String',sprintf('time = %g',time(t_idx)));
end
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by