简体   繁体   English

Matlab 下标赋值维度不匹配错误

[英]Matlab Subscripted assignment dimension mismatch error

I'm trying to perform row multiplication with two matrices: A and B .我正在尝试使用两个矩阵执行行乘法: AB

A Subscripted assignment dimension mismatch error is thrown on the line C(1,i) = A(i,:)*B;C(1,i) = A(i,:)*B;行上抛出下Subscripted assignment dimension mismatch错误C(1,i) = A(i,:)*B; . .

Do I have a syntax error that is causing the dimensions on the left and right sides of the = sign to be unequal?我是否有语法错误导致=符号左侧和右侧的尺寸不相等?

function C = rowproduct(A,B)

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

C=zeros(1,n);

if( m == p)
    for i=1:n
        C(1,i) = A(i,:)*B;
    end
else
    error('matrix dimension mismatch');
end
end

try to replace C(1,i) = A(i,:)*B;尝试替换C(1,i) = A(i,:)*B; with C(i,:) = A(i,:)*B;C(i,:) = A(i,:)*B;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM