Converting a row to diagonal matrix
古いコメントを表示
Hello I have a row containing 120 elements i want to convert this row to 16*16 diagonal matrix with 0 in the diagonal. I tried commands like reshape and diag but still not successful. Someone please give me insight.
EDIT:
Hello Thank you guys for answers. Sorry i didnt provided much details before:
I have data from a tomography device which i need to convert it to a matrix for the software to read the data i have is in this form 1 row and 120 columns:
M(1x120)= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
But the software understand this in the following format:

Please give me some insights how can i do it.
3 件のコメント
David Hill
2020 年 2 月 18 日
You description is not clear to me. Please show us what you want (example).
Matt J
2020 年 2 月 18 日
i want to convert this row to 16*16 diagonal matrix with 0 in the diagonal
If the result is to be both a diagonal matrix and to have zeros along the diagonal, then the matrix must simply be all zeros,
>> zeros(16)
MS
2020 年 2 月 19 日
採用された回答
その他の回答 (1 件)
Sky Sartorius
2020 年 2 月 18 日
Another guess at the intended meaning of the question could be that the values should be filled along the diagonals (instead of sequentially filling in by rows or columns):
data = 1:120;
ind = tril(true(16),-1);
[M, result] = deal(zeros(size(ind)));
M(ind) = data;
M = flipud(M');
newData = M(logical(M));
result(ind') = newData;
result = result + result'
カテゴリ
ヘルプ センター および File Exchange で Operating on Diagonal Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!