leading zeros on matrix variable

6 ビュー (過去 30 日間)
Luís Asevedo
Luís Asevedo 2019 年 4 月 6 日
回答済み: madhan ravi 2019 年 4 月 6 日
hello,
I have for example a matrix variable A = [ 1; 10, 100] and i want add leading zeros to obtain A=[001; 010;100]. This matrix is an exemple, i need to know how to do for all diferent matrix and not this matrix in specific!
Thank you !!
  1 件のコメント
John D'Errico
John D'Errico 2019 年 4 月 6 日
編集済み: John D'Errico 2019 年 4 月 6 日
Numbers conventionally don't have leading zeros. If you want to convert them to strings, then you can intentionally insert those leading zeros. But as numbers, they will not be displayed with leading zeros.

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

回答 (1 件)

madhan ravi
madhan ravi 2019 年 4 月 6 日
Agree with John,
S = ""+A;
Max = max(cellfun('prodofsize',S));
Result = cellfun(@(x)regexprep(strjoin([""+zeros(1,Max-numel(x)) x]),' ',''),S,'un',0)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by