Qam*_*mar 0 matlab transpose vector
有没有人知道如何[6 8 2]在不使用内置命令的情况下将行向量转换为列向量.我想在没有for循环的情况下这样做.请给我一个想法.有人问我这是家庭作业,我说不,这是我工作的一部分.我试图使用hdl编码器将MATLAB代码转换为vhdl,但hdl编码器似乎不支持转置功能.
Dan*_*Dan 10
一些选择:
R = 1:10; %// A row vector
%// using built-in transpose
C = R'; %'// be warned this finds the complex conjugate
C = R.'; %'// Just swaps the rows and columns
C = transpose(R);
%// Flattening with the colon operator
C = R(:); %// usually the best option as it also convert columns to columns...
%// Using reshape
C = reshape(R,[],1);
%// Using permute
C = permute(R, [2,1]);
%// Via pre-allocation
C = zeros(numel(R),1);
C(1:end) = R(1:end);
%// Or explicitly using a for loop (note that you really should pre-allocate using zeros for this method as well
C = zeros(numel(R),1); %// technically optional but has a major performance impact
for k = 1:numel(R)
C(k,1) = R(k); %// If you preallocated then C(k)=R(k) will work too
end
%// A silly matrix multiplication method
C = diag(ones(numel(R),1)*R)
Run Code Online (Sandbox Code Playgroud)