Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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

Respuestas (1)

Rik
Rik el 11 de Mayo de 2019
Editada: Rik el 12 de Mayo de 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)

Categorías

Más información sobre Language Fundamentals en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by