필터 지우기
필터 지우기

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