Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Accessing data in cell array

1 vue (au cours des 30 derniers jours)
Anna
Anna le 26 Août 2013
Clôturé : MATLAB Answer Bot le 20 Août 2021
I have a cell array that looks something like
0 a 01
1 b 11
2 c 101
3 d 1100
The data inside is stored as strings. How could I implement a for loop with the use of strfind in a function where the value passed is a number from the first column e.g 1,2,3 and I want to return the corresponding 1 and 0 pattern from the third column.
I can access individual elements of the array by typing at the command line: filename{1,3} etc
Help is much appreciated, i'm only a beginner programmer. I have noticed it picks up the ascii too, how can I stop that?
Thanks.
  2 commentaires
dpb
dpb le 26 Août 2013
What do you mean by it picks up the ascii too? You mean that strfind thinks a '1' by itself is also a '1' in a string such as '101'? That kinda' goes w/ the territory if you're storing all the data as character. If you mean something else, amplify.
To search only the first column, pass only the first column to strfind
strfind(c{:,1},targetnumstr) and return the third column using that result as the row index --
res=c{strfind(c{:,1},targetnumstr),3};
NB: aircode, watch for typos, imbalanced parens, etc., etc., ... :)
Jan
Jan le 26 Août 2013
"Cell array" and "data stored as string" could mean:
C = {'0 a 01', '1 b 11', '2 c 101', '3 d 1100'}
Or
C = {'0', 'a', '01'; '1', 'b', '11'; '2', 'c', '101'; '3', 'd', '1100'}
Further combinations are possible. So please post exactly what you have as input and what "return the 1 and 0 pattern" mean.

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by