how to identify empty , non-empty char matrix condition?

23 ビュー (過去 30 日間)
MP
MP 2022 年 7 月 18 日
回答済み: MP 2022 年 7 月 18 日
I have a matrix "A" with size 4x8 char and having values:
'01:04:00'
'01:03:00'
' '
'01:01:00'
I want to identify the index of empty char. I.e. 3rd one.
I tried,
% first one
A == ""
% second one
A == ''
% third one
isempty(A)
% forth one
isspace(A)
% fifth one
A == ' '
% sixth one
A == " "
% everything shows zero output.
Can anyone please help?
Any help will be greatly appriciated.

採用された回答

Stephen23
Stephen23 2022 年 7 月 18 日
編集済み: Stephen23 2022 年 7 月 18 日
M = [...
'01:04:00'
'01:03:00'
' '
'01:01:00'];
strcmp('',cellstr(M)) % CELLSTR removes trailing whitespace characters.
ans = 4×1 logical array
0 0 1 0
cellfun(@isempty,cellstr(M)) % CELLSTR removes trailing whitespace characters.
ans = 4×1 logical array
0 0 1 0
all(M==32,2) % match space character only.
ans = 4×1 logical array
0 0 1 0
all(M==' ',2) % match space character only.
ans = 4×1 logical array
0 0 1 0
all(isstrprop(M,'wspace'),2) % match any whitespace character.
ans = 4×1 logical array
0 0 1 0
  1 件のコメント
MP
MP 2022 年 7 月 18 日
Really!!
Indeed that made a great help!
Thank you very much.

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

その他の回答 (1 件)

MP
MP 2022 年 7 月 18 日
@Stephen23: Could you please also look into my another question?
https://in.mathworks.com/matlabcentral/answers/1762535-how-to-find-the-nearest-matrix-between-two-matrices?s_tid=srchtitle

カテゴリ

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