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!