How I can use Unique command to remove duplicates but still can use the data of the removed duplicates?

1 visualización (últimos 30 días)
I have an excel file that has strings of species name and their Antoine's coefficients. I am willing to import the data into a pop up menu in GUI without having the duplicated strings (Species). However, I would still need to use the data of duplicated string to solve for Antoine's coefficients because they vary according to the min and max temperature (and that is why there are duplicates). I attached the excel file I am willing to use, and the code I started with. Note that the code must be able to identify any additional compound in the excel sheet.
[num,text]=xlsread('Antoine_Coefficient.xlsx');%import the data from excel sheet and store them in a cell array of number and text
N=length(text)-2;%Specifying the length of the text cell array(the substraction of 2 is due to the exta cells)
global compound; %make compound global so it is reused in callbacks
compound=text(3:N+2,1);%assign the name of the given compounds(2 is added after being substracted to update the cell infomration and not confuse it with Antoine's coefficient.
global A B C Tmin Tmax %Make All Antoins' coefficinet global in order to reuse them when calledback
A=num(1:N,1);%assign the A coefficient from the excel file
B=num(1:N,2);%assign the B coefficient from the excel file
C=num(1:N,3);%assign the C coefficient from the excel file
Tmin=num(1:N,4);%assign the Tmin from the excel file
Tmax=num(1:N,5);%assign the Tmax from the excel file
set(handles.popupmenu1,'String',compound);%adding the compounds to the pop up menu in the form of a string
  3 comentarios
Jan
Jan el 29 de Nov. de 2016
Please post the relevant part of the code only. It is a waste of time, if all users try to locate the concerned lines. Details like "Antoine's coefficients" are confusing only. For this problem they are strings or array. So what is your input exactly and what is the wanted output?
Khalil Ishaq
Khalil Ishaq el 29 de Nov. de 2016
Editada: Khalil Ishaq el 29 de Nov. de 2016
I am trying to apply the unique command in order to remove the duplicate compounds ; however, I still want the coefficients to be in order with the compounds, so later I can set an if statement that asks the user to choose the temperature range of the duplicated compounds (if selected).

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 29 de Nov. de 2016
Editada: Jan el 29 de Nov. de 2016
Do not use globals to share data between callbacks. Use either the ApplicationData (e.g. as by guidata) or the 'UserData' of e.g. the figure.
[uC, iA, iC] = unique(compound);
handles.Compounds.iA = iA;
handles.Compounds.iC = iC;
handles.Compounds.Coeff = rand(1, numel(compound)); % ???
handles.Compounds.Name = uC; % Stored as 'String' also in the next line:
set(handles.popupmenu1, 'String', uC);
...
guidata(FigureHandle, handles); % Update the handles struct
Then in the callback:
function popup1Callback(PopMenu1H, EventData)
handles = guidata(PopMenu1H);
index = get(PopMenu1H, 'value');
string = handles.Compounds.Name{index}
origIndex = handles.Compounds.iC(handles.Compounds.iA(index));
origMatch = (handles.Compounds.iC == origIndex);
origCoeff = handles.Compounds.Coeff(origMatch)
  1 comentario
Guillaume
Guillaume el 29 de Nov. de 2016
Editada: Guillaume el 29 de Nov. de 2016
"Do not use globals." Indeed, they make the lifetime of variables very difficult to track and will lead to bugs.
Even worse than globals are globals named A, B and C, names that have absolutely no meaning and make understand the code an hopeless task (speaking from experience here, having had to debug/refactor such awful code).

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by