Read numbers and characters

9 ビュー (過去 30 日間)
Patrícia Falcão
Patrícia Falcão 2018 年 8 月 9 日
コメント済み: Stephen23 2018 年 8 月 13 日
Hi!
I am trying to read an output from a software that gives me numbers and semicolons, commas, minus and points. The output can be either an excel file ou txt file. If I choose the excel file and open it in matlab, the output is like this:
1
9
.
3
1
2
5
COMMA
2
5
.
1
2
5
0
COMMA
-
1
3
.
7
But I want to matlab recognize if it is a number or a character. In reality, what I want to do is to have "19.3125, 25.1250, -13.7,..." and for that I need matlab to recognize what is a number and not. Can you help me?
  5 件のコメント
Stephen23
Stephen23 2018 年 8 月 9 日
編集済み: Stephen23 2018 年 8 月 9 日
'COMMA means ","'
Sure, we know what "comma" means. But which of these is actually in the text file?:
  1. ,
  2. COMMA
This would be much simpler if you just uploaded a sample text file by clicking on the paperclip button.
Patrícia Falcão
Patrícia Falcão 2018 年 8 月 9 日
You're right. It is uploaded the txt file. But I don't want the first numbers, just the next to the first comma. What I have already explained to Stephen Cobeldick.

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

採用された回答

Stephen23
Stephen23 2018 年 8 月 9 日
編集済み: Stephen23 2018 年 8 月 9 日
Using a simple text file (this will be much easier than processing an Excel file):
>> str = fileread('temp0.txt');
>> str = regexprep(str,'\s+','');
>> vec = sscanf(str,'%fCOMMA',[1,Inf])
vec =
19.312 25.125 -13.700
The test file is attached. If you had actually uploaded your file then I could have tested my code on that: no sample data means I have to invent my own data, which may or may not be the same as what you have.
  4 件のコメント
Patrícia Falcão
Patrícia Falcão 2018 年 8 月 13 日
Thank you very much Stephen Cobeldick! You helped me a lot!
Stephen23
Stephen23 2018 年 8 月 13 日
@Patrícia Falcão: I hope that it helps! Remember to accept the answer that helped you most: this give reputation points to the volunteers who help you on this forum.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by