Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
matlab,用户将矩阵输入变量_Matlab_Matrix - Fatal编程技术网

matlab,用户将矩阵输入变量

matlab,用户将矩阵输入变量,matlab,matrix,Matlab,Matrix,我有这个matlab的乘法矩阵的代码,我如何让用户添加矩阵,然后在代码中使用矩阵 eg[n,m]=输入(此处为用户输入矩阵) 您可以在脚本中使用: A = input('input array A '); B = input('input array B '); [n,m] = size(A); [p,q] = size(B); C = zeros(n,p); if p~=m error('Inner Matrix Dimensions Must Agree.') end for

我有这个matlab的乘法矩阵的代码,我如何让用户添加矩阵,然后在代码中使用矩阵

eg[n,m]=输入(此处为用户输入矩阵)


您可以在脚本中使用:

A = input('input array A ');
B = input('input array B ');

[n,m] = size(A);
[p,q] = size(B);
C = zeros(n,p);

if p~=m
    error('Inner Matrix Dimensions Must Agree.')
end

for k = 1:n
    for j = 1:q
        temp=0;
        for i = 1:p
            temp = temp+(A(k,i)*B(i,j));
        end
        C(k,j) = temp;
    end
end
或者您可以将上述内容作为函数写入:

function C = matrixmultiply(A,B)

[n,m] = size(A);
[p,q] = size(B);
C = zeros(n,p);

if p~=m
    error('Inner Matrix Dimensions Must Agree.')
end

for k = 1:n
    for j = 1:q
        temp=0;
        for i = 1:p
            temp = temp+(A(k,i)*B(i,j));
        end
        C(k,j) = temp;
    end
end

end
function C = matrixmultiply(A,B)

[n,m] = size(A);
[p,q] = size(B);
C = zeros(n,p);

if p~=m
    error('Inner Matrix Dimensions Must Agree.')
end

for k = 1:n
    for j = 1:q
        temp=0;
        for i = 1:p
            temp = temp+(A(k,i)*B(i,j));
        end
        C(k,j) = temp;
    end
end

end