フィルターのクリア

How to replace the empty cells in a cell array by a 4-bits string?

34 ビュー (過去 30 日間)
Sarah A
Sarah A 2020 年 1 月 18 日
コメント済み: Sarah A 2020 年 1 月 25 日
Hello,
How to replace the empty cells " [ ] " in the attached matrix to a 4-bits string we can convert the whole array matrix to double.
For example,
if we have thw following row:
[ '0001', '0101' , '1010', [ ], [ ], [ ], '1111']
it becomes:
[0,0,0,1,0,1,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1]

採用された回答

Akira Agata
Akira Agata 2020 年 1 月 19 日
How about the following?
load('Key.mat');
idx = cellfun(@isempty,Key); % Find the indexes of empty cell
Key(idx) = {'0000'}; % Replace the empty cells with '0000'

その他の回答 (1 件)

Stephan
Stephan 2020 年 1 月 18 日
編集済み: Stephan 2020 年 1 月 18 日
load('Key.mat');
Key1 = Key(:);
Key1 = reshape(replace(string(char(Key1{:}))," ","0000"),size(Key,1),size(Key,2));
results in a string array filing up all empty elements with "0000".
  2 件のコメント
Sarah A
Sarah A 2020 年 1 月 19 日
it is not working, I got this error:
Undefined function 'replace' for input arguments of type 'char'.
Walter Roberson
Walter Roberson 2020 年 1 月 19 日
Which MATLAB version are you using? R2016a or earlier likely.

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

カテゴリ

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