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!