How to turn an 1x1x3 array to a 1x3 vector?

70 ビュー (過去 30 日間)
Z Yerby
Z Yerby 2019 年 6 月 21 日
コメント済み: Z Yerby 2019 年 6 月 24 日
Various manipulations I perform in my script create a 1x1x3 array which I then need to produce a dot product with a 1x3 vector. That's not playing together so I need to turn my 1x1x3 array into a 1x3 vector. I figure I can use vector=[array(1,1,1), array(1,1,2), array(1,1,3) ]; but I don't like how that looks and figure I could cut a line out if there was a function call that does the same thing. I assume there is one because this seems like something an existing function call would do but I cannot find it. Is there something I could use instead of vector=[array(1,1,1), array(1,1,2), array(1,1,3) ];?

採用された回答

madhan ravi
madhan ravi 2019 年 6 月 21 日
編集済み: madhan ravi 2019 年 6 月 21 日
reshape(array,1,[]) % or squeeze() transposed
  1 件のコメント
Z Yerby
Z Yerby 2019 年 6 月 24 日
I ended up using squeeze and it worked for my purposes well. Thanks.

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

その他の回答 (1 件)

Bruce Elliott
Bruce Elliott 2019 年 6 月 21 日
Yes, there is an existing function to do that: permute().
Here's the help text:
% permute Permute array dimensions.
% B = permute(A,ORDER) rearranges the dimensions of A so that they are in
% the order specified by the vector ORDER. The resulting array has the
% same values as A but the order of the subscripts needed to access any
% particular element is rearranged as specified by ORDER. For an N-D
% array A, numel(ORDER)>=ndims(A). All the elements of ORDER must be
% unique.
%
% permute and IPERMUTE are a generalization of transpose (.')
% for N-D arrays.
%
% Example:
% a = rand(1,2,3,4);
% size(permute(a,[3 2 1 4])) % now it's 3-by-2-by-1-by-4.
%
% See also ipermute, circshift, size.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by