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

1 vue (au cours des 30 derniers jours)
jaah navi
jaah navi le 11 Mai 2019
Modifié(e) : Rik le 12 Mai 2019
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

Réponses (1)

Rik
Rik le 11 Mai 2019
Modifié(e) : Rik le 12 Mai 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)

Catégories

En savoir plus sur Language Fundamentals dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by