Colon operator for cells

Hello,
i have the following table:
Tab1=table('Size',[9 2],'VariableTypes',{'cell','double'},'VariableNames',{'Description','Value'});
Tab1.Description(:)={'Name1','Name2','Name3','Name4','Name5','Name6','Name7','Name8','Name9'};
Tab1.Value(:)=[5,10,17,7,25,75,23,47,54];
Tab1=
Description Value
_______ _______
'Name1' 5
'Name2' 10
'Name3' 17
'Name4' 7
'Name5' 25
'Name6' 75
'Name7' 23
'Name8' 47
'Name9' 54
I want to access Description from 'Name3' until 'Name8', is there a way to do it with the concrete content ('Name3' and 'Name8') and without using the rows/columns?
So i want the solution of the following calculation, but the calculation itself should be different:
Tab1.Description(3:8,1);
'Name3'
'Name4'
'Name5'
'Name6'
'Name7'
'Name8'
I am searching for a solution similar to:
Tab1.Description({'Name3'}:{'Name8'});
This doesnt work, because of: Undefined operator ':' for input arguments of type 'cell'.
I will greatly appreciate any assistance.

Answers (1)

idx="Name"+(3:8);
Tab1(ismember(Tab1{:,1},idx),:)

4 Comments

Thank you sir! This solution is only possible with the example names given. Is there also a solution if i swap names, for example 'Name2' is now 'Max' and 'Name3' is now 'Linda'?
Tab1=
Description Value
_______ _______
'Name1' 5
'Name2' 10
'Max' 17
'Name4' 7
'Name5' 25
'Name6' 75
'Name7' 23
'Linda' 47
'Name9' 54
So solution would look like:
'Max'
'Name4'
'Name5'
'Name6'
'Name7'
'Linda'
For older versions:
idx = regexp(sprintf('Name%d\n',3:8),'(\w*)','match');
% or
idx = sprintfc('Name%d',3:8); % undocumented
So mention the idx as is and then use ismember() ?
idx = {'Max'
'Name4'
'Name5'
'Name6'
'Name7'
'Linda'};
Tab1(ismember(Tab1{:,1},idx),:)
Sorry about the circumstances. Like this i would have the solution i want (idx) by just writing it down. I just need variable description, the corresponding value is not needed. Imagine there are way more rows with various names between 'Max' and 'Linda' and i dont even no them. I just know that 'Max' and 'Linda' are unique in description. So is there a way to "cut out" from Tab1.description every entry from 'Max' to 'Linda' including both?

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Asked:

on 22 Apr 2019

Commented:

on 22 Apr 2019

Community Treasure Hunt

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

Start Hunting!