get a subcell from a bigger cell
Ältere Kommentare anzeigen
I have a cell of 10x9 named 'a', each index contains a string. How can i create a sub cell if i have two vectors (f,c) with the indexes that i want. e.g. imagine a 2x3 cell a and indexes f and c
a={('this'), ('is') ,('big');('he') ,('buys') ,('it')}
f=[1,1,2];
c=[1,2,3];
the result i want is b={('this'), ('is');('it'),('')}
3 Kommentare
Jan
am 5 Feb. 2018
There are no parentheses around the strings:
a = {'this', 'is', 'big'; 'he', 'buys', 'it'}
Now please explain, why for [1,1,2] the cell {'this', 'is'} is created. What is the relation between the indices and the output? Of course we could try to guess this, but it is more efficient, if you explain it.
Miguel Reina
am 5 Feb. 2018
Jan
am 5 Feb. 2018
Wouldn't it be easier to apply directly:
a(b)
Antworten (1)
Guillaume
am 5 Feb. 2018
Use ind2sub:
a(ind2sub(size(a), f, c))
The result will be 1x3 vector not an arbitrary sized array.
Kategorien
Mehr zu Operators and Elementary Operations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!