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

1 view (last 30 days)
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

Answers (1)

Rik
Rik on 11 May 2019
Edited: Rik on 12 May 2019
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)

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!