How to extract information from cell?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello
Well , i have a file which is a cell 47x1. In one of the rows have Lastname=Ahlers I only need Ahlers.The other case is when i have character +numbers, here I have dimension=2 only I need 2,other example is CollX=-5.9 only i need -5.9.
Any idea would be really appreciated guys thanks
Ah I dont know the last name or any data from the file. The idea would be to get the name or value. I need the values (numbers) to run my code,they are parameters inside of my code. Each file is a different patient and each patient has different values.
댓글 수: 0
채택된 답변
Robert Cumming
2011년 7월 20일
use strfind to find the equal sign and then extract out the data to the right hand side of the equals, i.e.
NEWVAR = str2num(YOURCELL{YOUR_INDEX}(strfind ( YOURCELL{YOUR_INDEX}, '=' )+1:end))
in this case: you have a string "CollX=-5.9"
YOURCELL{1} = 'CollX=-5.9'
NEWVAR = str2num(YOURCELL{1}(strfind ( YOURCELL{1}, '=' )+1:end))
추가 답변 (1개)
Jan
2011년 7월 20일
E.g. by using STRTOK:
C = {'Lastname=Ahlers', 'dimension=2', 'CollX=-5.9'};
[dummy, C] = strtok(C, '=');
strrep(C, '=', '');
댓글 수: 3
Jan
2011년 7월 20일
@isabong: Obviously I do not understand what you have and what you want. Sorry for trying to guess such details.
What does "I have a file which is a cell 47x1" mean exactly? And "I only need Ahlers"? Do you want to dremove the string "Lastname=" in the file? Or do you want to delete it in the cell string? Or do you want to get the string behind "Lastname=" as separate variable? You see, your question leave some space for interpretations.
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!