MATLAB Answers

0

operations on multiple plots

Asked by Lorenzo Mattera on 15 Sep 2019
Latest activity Commented on by Lorenzo Mattera on 19 Sep 2019
I measure time of flight spectra of ions ejected from a solid surface (TOF mass spectrometry) as a I(t) function.
I transform the time scale into a mass scale by knowing that two peaks in I(t) correspond to two masses (s1 and s2)
in this way now I have both I(t) and I(m) which I plot in two subplots.
Using hold on I can superimpose different spectra running the program for different data set
It works fine this way but I would like to "add" a couple of features which could be quite usefull in data analysis:
-insert a legend in order to know whick dataset corresponds to a given line in the plot
-selectively eliminate one or more lines from the figure when it becomes too messy or to directely compare two (or more) specific dataset on the same subplot
I do not think that it can be done in this way (or at least I could not figure out how to do it)
Any suggestion will be greatly appreciated
Regards
Renzo
the code I am using follows
format shortEng
% assign two peaks in the TOF spectrum to two masses
%tI is the peak time corresponding to the first mass (s1 peaked up from a
% the table tabellamasse), tII the time corresponding to the second
% mass(s2)
[~, ~, tabellamasse]=xlsread('C:\Users\renzo\Desktop\mis\tabellamasse.xlsx');
s1='Ni58';
tI=8.115;
s2='Ni60';
tII=8.264;
indx = strcmp(tabellamasse,s1);
rowNum = indx==1;
s1=cell2mat(tabellamasse(rowNum,2));
indx = strcmp(tabellamasse,s2);
rowNum = find(indx==1);
s2=cell2mat(tabellamasse(rowNum,2));
%
m1=[s1,tI];
m2=[s2,tII];
%read data file
[file,path] = uigetfile('C:\Users\renzo\Desktop\TAC\*.dat');
if isequal(file,0)
disp('User selected Cancel');
else
disp(['User selected ', fullfile(path,file)]);
end
selectedfile=fullfile(path,file);
% read data from data file
M =importdata(selectedfile);
T=M(:,1);
T(1)=[];
Is=M(:,2);
Is(1)=[];
T=T/1000; %time in us
mm1=[round(m1(1,1),0), m1(1,2)];
mm2=[round(m2(1,1),0), m2(1,2)];
%calculate constants A1 and t0 to transform time to mass
A1=(m2(1,2)-m1(1,2))/(sqrt(m2(1,1))-sqrt(m1(1,1)));
t0=m2(1,2)-A1*sqrt(m2(1,1));
X1=['A1= ', num2str(A1),' t01= ',num2str(t0)];
L1=[num2str(mm1)];
L2=[num2str(mm2)];
L3=[num2str(m1)];
L4=[num2str(m2)];
massa1=((T-t0)/A1).^2;
mmax=((16-t0)/A1)^2;
% first subplot Intensity vs. mass
hold on
subplot(2,1,1)
plot(massa1,Is)
title(path)
legend({['I massa ' L1 newline, 'II massa ' L2 newline, X1]})
set(gca,'XMinorTick','on','YMinorTick','off','Xgrid','on','TickDir','out')
grid minor
xlim([0.1 mmax])
xticks(0: 5: mmax)
xlabel('mass (a.u.)')
% second subplot original data (intensity vs. time)
subplot(2,1,2)
plot(T,Is)
legend({[file newline, L3 newline, L4]})
set(gca,'XMinorTick','on','YMinorTick','off','Xgrid','on','TickDir','out')
grid minor
xlim([0 20])
xlabel('time (us)')

  0 Comments

Sign in to comment.

Products


Release

R2019a

1 Answer

Answer by Raunak Gupta on 19 Sep 2019

Hi,
In my understanding you are trying to assign legend to different dataset that are plotted on each sub plot as well as adding a GUI based option that can select or eliminate the lines from subplot.
You can use App Designer for creating an app which can be useful for getting control on the plot you want to see. First you may make a function that does the plotting for a single dataset. After which you need to the number of datasets you are working with. You may use a checkbox UI Object for each dataset. This object with the help of callback can control whether to show a specific data line or not by simply checking or unchecking. This will also create a legend as well as a way to remove or show a particular line. The function for plotting will come in ValueChangedFcn.
For more knowledge about UI Object and Callbacks you may refer to the following links.

  3 Comments

Thank You for the answer
Somenthing which is not clear to me:
... After which you need to the number of datasets you are working with. ...
You mean that I have to know in advance the number of data set I will work on?
I would rather prefer to add new data sets as the experiment goes on
Renzo
For getting the legend for each dataset you may need to know the number of dataset so that a proper UI Checkbox can be created. Dynamically adding the UI object for each dataset may not be possible as a seperate create function and ValueChangeFcn need to written for each UI Object.
Ok, I undestand
Thanks

Sign in to comment.