Counting the Size of X Indices of a Matrix
2 ビュー (過去 30 日間)
古いコメントを表示
I am trying to find out how to input a random matrix of random dimensions and a random number of entries in each dimension, and output "dimension a = 5 entries, dimension b = 4 entries" etc without previously specifying how many there will be.
So for example, if I have matrix A which is 4x5x2 (for whatever reason), I want a series of operations that will output: Dimension A = 4, Dimension B = 5, Dimension C = 2". I have been trying to do this with "F = Size(A)", except I have to input "[a, b, c] = Size(A)" to get the output I want. And I can't find a way to input a matrix (so that it identifies the size of each dimension) without already saying how many dimensions there are.
Here's the function I have right now:
function Plethos = Plethos(X)
% This function will tell you what the plethos of a Holor index is.
Number = Valence(X);
Start = 97;
End = 97 + Number - 1;
if Start == End;
Index = char(Start)
else
Index = char(Start:End)
end
Final = End - Start + 1
%-------------------------------------------%
Index2 = str2double(Index)
Index2 = sym('Index', [1, Final])
Index2 = size(X)
end
If you're wondering, Valence(X) is a function I have which already counts how many dimensions (or indices) a matrix has, from the scalar (Valence = 0), to a vector (Valence = 1), to a matrix (Valence = 2), to a tensor/4x5x2 matrix (Valence = 3), etc.
Everything goes perfectly, so that "Index" becomes "abcde...." until I have a letter for each dimension of the input. Everything is perfect until the comment line. I tried using sym(A) to make a matrix out of the letters with them as variables, but all of the str2___ functions have a null output, and even if they didn't, Index2 = size(X) (which is meant to perform [a b c] = size(X) so that the output gives a = 4, b = 5, c = 2) doesn't work that way. So I would like help on how to make a value which contains a matrix of variables, which will then be used to measure each dimension of the input just like [a b c] = Size (X) would normally output.
0 件のコメント
採用された回答
madhan ravi
2020 年 11 月 6 日
Naming variables is a bad idea
Dimensions = num2cell(size(rand(2,3,4))) % simply use a cell array
celldisp(Dimensions)
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!