Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Accessing data in cell array

1 Ansicht (letzte 30 Tage)
Anna
Anna am 26 Aug. 2013
Geschlossen: MATLAB Answer Bot am 20 Aug. 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 Kommentare
dpb
dpb am 26 Aug. 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 am 26 Aug. 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.

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by