我一直试图运行它并且不知道出了什么问题.我把它保存为test.m. 我在编辑器中单击运行,在matlab命令窗口中,它表示没有足够的输入参数.我觉得我错过了一些完全明显的东西,但我无法发现问题.
function y = test(A, x)
%This function computes the product of matrix A by vector x row-wise
% define m number of rows here to feed into for loop
[ma,na] = size(A);
[mx,nx] = size(x);
% use if statement to check for proper dimensions
if(na == mx && nx == 1)
y = zeros(ma,1); % initialize y vector
for n = 1:ma
y(n) = A(n,:)*x;
end
else
disp('Dimensions of matrices do not match')
y = [];
end
end
Run Code Online (Sandbox Code Playgroud) 我试图找到A具有最大值的矩阵条目.我已经生成了矩阵A,除了矩阵A中的条目的最大值之外,我怎么能要求MATLAB返回四个索引
for i = 1:size(CB,2)
for j=1:size(CB,2)
for k=1:size(CB,2)
for l=1:size(CB,2)
A(i,j,k,l)= (abs( conj(transpose([CB(:,i); CB(:,j)]))*MATRIX* [CB(:,k); CB(:,l)])^2);
end
end
end
end
Run Code Online (Sandbox Code Playgroud) 我试图将sed的输出存储到变量中,但输出与我的预期不同.
我的测试如下
$ foo="this is (foo)"
$ x="$(sed 's/(/\\\\(/g' <<< $foo)"
Run Code Online (Sandbox Code Playgroud)
预期的结果是:
$ echo $x
this is \\(foo)
Run Code Online (Sandbox Code Playgroud)
我得到的结果是:
$ echo $x
this is \(foo)
Run Code Online (Sandbox Code Playgroud)
但是,当我没有将输出分配给变量时,结果是预期的结果:
$ sed 's/(/\\\\(/g' <<< $foo
this is \\(foo)
Run Code Online (Sandbox Code Playgroud)
为什么我的输出存储失败?
注意 :
我也尝试了以下命令行,它们都以相同的结果结束:
$ x=`sed 's/(/\\\\(/g' <<< $foo`
$ x=$(sed 's/(/\\\\(/g' <<< $foo)
$ x=`echo $foo | sed 's/(/\\\\(/g'`
$ x=$(echo $foo | sed 's/(/\\\\(/g')
Run Code Online (Sandbox Code Playgroud)