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

1 次查看(过去 30 天)
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 个评论
Trick Verzosa
Trick Verzosa 2016-8-23
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by