could anyone help me how to check the size of bigger matrix and run the code accordingly.

1 次查看(过去 30 天)
I am having two matrices of different sizes A and B generated by the code.
When I run the code in some cases, size of A will be greater than B and in some cases size of B will be greater than A.
case1,when A=[4x2] and B=[1x2],I have done with the following code
[jj,kk]=size(A)
[jjj,kkk]=size(B)
zz=zeros(jj,kk)
zz(1:jjj,1:kkk)=B
C=(A-zz)
case 2, when B=[4x2] and A=[1x2],I have done with the following code
[jj,kk]=size(B)
[jjj,kkk]=size(A)
zz=zeros(jj,kk)
zz(1:jjj,1:kkk)=A
C=(B-zz)
Using these two cases I need to first check which matrix size is bigger and based upon it i need to choose either case 1 code or case 2 code.
could anyone please help me on this

回答(1 个)

Rik
Rik 2019-5-11
编辑:Rik 2019-5-12
This code should work:
if numel(A) > numel(B)
A_=A;B_=B;
else
A_=B;B_=A;
end
[jj,kk]=size(A_)
[jjj,kkk]=size(B_);
zz=zeros(jj,kk);
zz(1:jjj,1:kkk)=B_;
C=(A_-zz)

类别

Help CenterFile Exchange 中查找有关 Language Fundamentals 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by