Info
此问题已关闭。 请重新打开它进行编辑或回答。
Accessing data in cell array
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
dpb
2013-8-26
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
2013-8-26
"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.
回答(0 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!