Create multidimensional matrices from two multidimensional cells.
古いコメントを表示
Dear all, I have a cell f{k} with k matrices inside it, where k=1:96. For each k, the matrices have different lengths. For eg. length (f{1})=13 and length (f{96})=80. In addition, I have another cell W{k} with k=1:96. Again, for each k, the matrices have different lengths. For eg. length (W{1})=49 and length (W{96})=65.
Following is the output for cell f, for the first 9 elements of cell f:
Columns 1 through 9
[13×1 double] [24×1 double] [36×1 double] [43×1 double] [48×1 double] [65×1 double] [81×1 double] [95×1 double] [107×1 double]
Similarly, following is the output for cell W, representing first 9 elements of W:
Columns 1 through 9
[1×49 double] [1×49 double] [1×49 double] [1×48 double] [1×47 double] [1×49 double] [1×49 double] [1×48 double] [1×47 double]
Now, for each k=1:96, I want to create a matrix (say M) which should contain indices of W and f. For eg. if i put M(1), I should get matrix with size (f{1}*W{1}). Note that f{1} and W{1} have different lengths and new matrices will be formed of different lengths, for each k.
Is this even possible? Please help me with this. Thank you in advance.
採用された回答
その他の回答 (1 件)
Jos (10584)
2018 年 2 月 8 日
The operator * may not do what you expect. Try this
A = [1 2 3] ; B = [4 5 6] ; C = [10 20 30 40 50]
% A * B % error
A * B.' % dot-product
% A * C % error
A.' * B % → matrix
A.' * C % → matrix
% A * C.' % error
What type of operation are you after?
Or do you want to do element-wise multiplication (.*)? Then the two vectors should have an equal number of elements. Anyways, here is a one-liner that might suit you:
M = arrayfun(@(k) F{k} * W{k}, 1:numel(F), 'un', '0)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!