Info

This question is closed. Reopen it to edit or answer.

How to search a cell array and then use the searched item to delete that row of the cell array

1 view (last 30 days)
Hi guys I am working on a project and i have gotten descently far but I have some confusion.
I am importing a excel spreedsheet into matlab and I have a program to add, search or delete from the information.
So far I have been able to add entrys no problem.
My issue is how can i search the cell array for one string then have the search be set to a variable that highlights the whole row? I will prompt the user for if they want to delete the entry or not.
Its a fairly simple code i think but I am not sure how to search. All input is appreciated thanks!
here is a sample of the cell array inputted from the spreedsheet data =
'Item For Sale' 'Price' 'Condition' 'carrier'
[ NaN] [ NaN] [ NaN] [ NaN]
'iphone 4s' [ 125] 'used' 'att'
'iphone 5s' [ 180] 'good' 'verizon'
'hi ' [ 225] 'used' 'sexy'
'first' [ 225] 'used' 'att'
'second' [ 3442] 'gfds' 'gfds'
'third' [ 1234] 'gfds' 'gfd'

Answers (1)

Image Analyst
Image Analyst on 7 Aug 2014
If you don't have nan's in it, it's pretty easy, using ismember:
spreadsheetData ={...
'Item For Sale' 'Price' 'Condition' 'carrier';...
%[ NaN] [ NaN] [ NaN] [ NaN];...
'iphone 4s' [ 125] 'used' 'att' ;...
'iphone 5s' [ 180] 'good' 'verizon';...
'hi ' [ 225] 'used' 'sexy' ;...
'first' [ 225] 'used' 'att' ;...
'second' [ 3442] 'gfds' 'gfds' ;...
'third' [ 1234] 'gfds' 'gfd'}
% Find row with "first" in it.
A = {'first'}; % Word to remove.
B = spreadsheetData(:,1); % First column of spreadsheetData.
% Find row # in B where 'first' occurs.
[~, rowToDelete] = ismember(A, B)
% Delete that row.
spreadsheetData(rowToDelete,:) = []

Tags

Community Treasure Hunt

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

Start Hunting!