Is it possible to delete a part of a cell

2 ビュー (過去 30 日間)
Julius Focke
Julius Focke 2022 年 3 月 3 日
コメント済み: Julius Focke 2022 年 3 月 4 日
Hello guys,
I´m stuck with a problem, is it possible to delete a certain part of a cell array?
Like, I have a cell with 0.1 sec. and I would like to delete the sec. , is it possible to do it?
And when, how can I realise it?
Thanks

回答 (1 件)

Image Analyst
Image Analyst 2022 年 3 月 3 日
編集済み: Image Analyst 2022 年 3 月 3 日
There are more compact ways, like using cellfun(), but they're pretty cryptic and hard to understand. A simple for loop is easy to understand:
ca = {'0.3 sec', '0.5 sec', 'Abc def'}
ca = 1×3 cell array
{'0.3 sec'} {'0.5 sec'} {'Abc def'}
for k = 1 : length(ca)
% Get cell contents and replace ' sec' with null.
ca{k} = strrep(ca{k}, ' sec', '');
end
% Show in command window
ca
ca = 1×3 cell array
{'0.3'} {'0.5'} {'Abc def'}
  2 件のコメント
Julius Focke
Julius Focke 2022 年 3 月 4 日
Thank you for your help, but it doesn´t work. I guess the problem is, that i thought it´s an array, but matlab says my time variable is a duration.
The Error I´ve got says: "Conversion to double from table is not possible."
Julius Focke
Julius Focke 2022 年 3 月 4 日
Update:
Now it finally works as expected. Because my Timevariable was a duration, I could use the function "time2num" and it converted the duration into a array without the sec. .

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by