フィルターのクリア

How to store rows of matrix into cell array?

44 ビュー (過去 30 日間)
ANURAG DEEPAK
ANURAG DEEPAK 2022 年 3 月 20 日
コメント済み: ANURAG DEEPAK 2022 年 3 月 20 日
Hello Sir,
How can i store different rows of matrix to cells in an cell array. For example: I have a matrix name 'tab' with 5 rows and i want to store every row of 'tab' into different cells of 'v_r' cell array.
tab = magic(5);
v_r = cell(1,5);
Output should be:

採用された回答

Image Analyst
Image Analyst 2022 年 3 月 20 日
編集済み: Image Analyst 2022 年 3 月 20 日
Try this:
tab = magic(5);
v_r = cell(1,5);
for row = 1 : size(tab, 1)
v_r{row} = tab(row, :);
end
v_r % Show in command window
v_r = 1×5 cell array
{[17 24 1 8 15]} {[23 5 7 14 16]} {[4 6 13 20 22]} {[10 12 19 21 3]} {[11 18 25 2 9]}
By the way, this just complicates things and is less efficient than just leaving them in a matrix. I would not recommend putting the rows into a cell array.

その他の回答 (1 件)

Matt J
Matt J 2022 年 3 月 20 日
編集済み: Matt J 2022 年 3 月 20 日
tab = magic(5);
v_r=num2cell(tab,2)
v_r = 5×1 cell array
{[ 17 24 1 8 15]} {[ 23 5 7 14 16]} {[ 4 6 13 20 22]} {[10 12 19 21 3]} {[ 11 18 25 2 9]}
  1 件のコメント
ANURAG DEEPAK
ANURAG DEEPAK 2022 年 3 月 20 日
Thank you sir.

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

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by