Pulling Part of a cell out
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I have a cell
'0040e3d8'
'0042f207'
'00431411' .....
What I want to do it pull the last value out. This cell can be of different lengths, but I always want the last value. I try c = temp(end), but it pulls the entire string in.
0 Commenti
Risposte (4)
Walter Roberson
il 23 Ott 2011
Your question is not clear. It would have been easier if you had indicate what you meant by "last value".
Have you tried temp{end} and temp{end}(end) ?
0 Commenti
the cyclist
il 23 Ott 2011
Is this what you mean?
c = {'0040e3d8';'0042f207';'00431411'};
c{end}(end)
0 Commenti
Image Analyst
il 23 Ott 2011
Just a guess. Did you want this:
ca = {'0040e3d8';'0042f207';'00431411'}
cm = cell2mat(ca)
lastChars = cm(:, end)
In the command window you'll see:
ca =
'0040e3d8'
'0042f207'
'00431411'
cm =
0040e3d8
0042f207
00431411
lastChars =
8
7
1
Note: This only works if all your strings are the same length (8 in this case). Of course if you knew in advance that they were all the same size you'd probably build it as a character array to start with rather than a cell array.
0 Commenti
Andrei Bobrov
il 23 Ott 2011
C = ...
{'00dgey46440e3d8'
'0042f207'
'00dfd431411'}
lasts = cellfun(@(x)x(end),C)
0 Commenti
Vedere anche
Categorie
Scopri di più su Cell Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!