Borrar filtros
Borrar filtros

How to match a cell from the first column to the next column like Excel Index - Match

1 visualización (últimos 30 días)
Hi! Please help. I have an Excel table loaded into matlab. The first column contains names while the second column contains the numerical values it represents. Here's the sample of the code used:
% --- Executes just before samplegui is made visible. function samplegui_OpeningFcn(hObject, eventdata, handles, varargin) ..... [~, material_text, ~] = xlsread('MyExcel.xlsx','A2:A35'); list = material_text; set(handles.popupmenu1,'string', list);
materialName = get(handles.popupmenu1, 'string'); materialRow = find(~cellfun('isempty',strfind(material_text,materialName)));
I used this to get the row number of the material selected in the pop up. Then,
% --- Executes on selection change in popupmenu1. function popupmenu1_Callback(hObject, eventdata, handles) ..... [~,~,material_all] = xlsread('MyExcel.xlsx','A2:D35'); materialValue = material_all{materialRow,2}; set(handles.edit6, density);
I used the row number to call the matching materialValue, but when I run the gui i get the following error:
Error using strfind PATTERN must be a single string.
I don't understand what the system's say that it must be a single string. Pls help. Thanks.
  1 comentario
Trick Verzosa
Trick Verzosa el 23 de Ag. de 2016
ok, I got the error... the code populates the popup menu with values from the loaded excel file, and when the strfind is used it reads the whole list again instead of the selected item from the popup menu.
Now, to rephrase my question, how can I make this function:
materialRow = find(~cellfun('isempty',strfind(material_text,materialName)))
read the selected item in the popup menu as one string instead of the whole list? Will highly appreciate any assistance. Thanks.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by