How to plot x-z plot which is varying in time (a dynamic plot)?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuesta aceptada
Voss
el 10 de Nov. de 2022
Editada: Voss
el 14 de Nov. de 2022
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
4 comentarios
Voss
el 14 de Nov. de 2022
Editada: Voss
el 14 de Nov. de 2022
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!