フィルターのクリア

How to extract information from cell?

4 ビュー (過去 30 日間)
isabong
isabong 2011 年 7 月 20 日
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.

採用された回答

Robert Cumming
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 件のコメント
isabong
isabong 2011 年 7 月 20 日
Thanks so much Robert...Very good solution. I dont really love programming but I love Matlab users.

サインインしてコメントする。

その他の回答 (1 件)

Jan
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
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.
isabong
isabong 2011 年 7 月 20 日
so so take it easy, sorry sorry yes? forgive me please!
step by step,
1)What does "I have a file which is a cell 47x1" mean exactly? Means, That I have information,and the file contents some parameters that i need to get for my code.
2)And "I only need Ahlers"? Sorry, only I need everything to the right hand after '='.Not all rows, only for a specific rows.
3)Or do you want to delete it in the cell string? mmm I really dont care, only I need extract some information to the righ hand.
4)Or do you want to get the string behind "Lastname=" as separate variable? mmm no, I dont need it. Only I need the information to the right hand as a variable. I dont need the cell,only to extract some values or names.The values gotten will be used in my code. If the row is CollX=-6 (the right hand after '=' is -6),so i need to get -6, and it should be available to be read in my code and take it as a parameter.
5)You see, your question leave some space for interpretations.
It's true! sorry again. I hope to be clear ! thanks

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by