Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Trick Verzosa
Trick Verzosa le 22 Août 2016
Commenté : Trick Verzosa le 23 Août 2016
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 commentaire
Trick Verzosa
Trick Verzosa le 23 Août 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by