Remove Whitespace & Text From Cell

If I have a cell like
[0.078 ms]
How can I remove both the whitespace and 'ms' to yield the result
[0.078]
Thanks,

1 件のコメント

Stephen23
Stephen23 2023 年 1 月 31 日
@Cesar Cabrera: please upload a sample data file by clicking the paperclip button.

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

回答 (2 件)

Kunal Kandhari
Kunal Kandhari 2023 年 1 月 31 日

0 投票

Hi,
You can make use of strrep: Find and replace substrings function

3 件のコメント

Cesar Cabrera
Cesar Cabrera 2023 年 1 月 31 日
Thanks Kunal, what if I have several thousand cells with the same isuse? All with varying amounts of spaces with the same string 'ms'?
Kunal Kandhari
Kunal Kandhari 2023 年 1 月 31 日
Hi Cesar,
You you please explain it is several thousand cell array or array of cells?
So that I can help you with that..
Can you write a dummy variable here?
Cesar Cabrera
Cesar Cabrera 2023 年 1 月 31 日
.txt file
|0.56 ms|
|0.86 ms|
|0.91 ms|
|0.25 ms|
T= readtable(example.txt)
I want to parse the data into a table from a .txt file like
0.56
0.86
0.91
0.25

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

Walter Roberson
Walter Roberson 2023 年 1 月 31 日

0 投票

See https://www.mathworks.com/help/matlab/ref/matlab.io.text.delimitedtextimportoptions.setvaropts.html#d124e755396 for the import options to ignore particular prefixes or suffixes. You would detectImportOptions and setvaropts and then pass the resulting options to readtable

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

製品

リリース

R2021a

質問済み:

2023 年 1 月 31 日

コメント済み:

2023 年 1 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by