How to convert each row of the matrix into a Character array, without using a for command?
2 ビュー (過去 30 日間)
古いコメントを表示
Matlab code:
A=rand(1e3,2);%just an example
for i=1:size(A,1)
B{i}=num2str(A(i,:));
end
Question: The cost time of the code is related to the size of A. How can I get the B without the For command and spend as less time as possible?
0 件のコメント
採用された回答
dpb
2019 年 4 月 3 日
Preallocate B may help just tad...
Alternatives to loop include
B=cellstr(num2str(A));
but what is end purpose for doing the conversion? Perhaps could avoid entirely??? The most time-saving optimization is the one that avoids doing the unneeded... :)
3 件のコメント
dpb
2019 年 4 月 3 日
Show a small subset example with data set...I suspect you can use ismember or other logical addressing to solve the problem directly without the text step at all...but need an example to ensure we're on the same page.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!