how can i know if x position of a vector is empty?

im trying this to know if that element(1,2) is empty or zero, to make a decision from that condition
if (ps1(1,2))==0
paredes1=1;
else
paredes1=length(ps1);
end
i was watching function like isempty or ismissing but its doesnt works.

1 comentario

per isakson
per isakson el 21 de Jun. de 2022
IMO, never use the function length(M) when M is an array. With vectors its ok. Use size(M,1) and size(M,2), respectively.

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 21 de Jun. de 2022
Element (1,2) of a numerical array will never be empty. It can't be. A whole array can be empty, or you can set a whole column or row of a matrix to null ([]) which will delete the column or row, but then it will be gone and the array will be smaller. It will not be empty.
To determine if that element is 0 you can simply do
if ps(1,2) == 0
% That element is 0.
end

Más respuestas (1)

Karan Kannoujiya
Karan Kannoujiya el 21 de Jun. de 2022

0 votos

Hi Erick,
So you want to check whether a element is ps1(in your case) is 0 or not.
So, isempty or ismissing function will not work here. Because 0 is itself a element. If in a vector there is 0 it doesn't mean it is empty or missing. For checking a vector element for 0 then you must check by indexing as you have done.
therefore, isempty function is used to check if a memory location is allocated whether there is an element present or not.
for e.g lets take a string str=["abc" "xyz" ""]
So, in str at pos 3 we have allocated memory but there is no element present there

5 comentarios

Hi karan bro, im so sorry i mean:
im trying this to know if that element(1,2) is empty , to make a decision from that condition.
per isakson
per isakson el 21 de Jun. de 2022
Editada: per isakson el 21 de Jun. de 2022
If element is a string array
str = ["abc","xyz",""];
find( strlength( str ) == 0 )
ans = 3
strlength( str(1,3) ) == 0
ans = logical
1
okok actually, are points (x,y), where the vector is filled, but i need to know if there is only a point or more, then im trying by this way because if i do l=length(ps1), with only a point this length give me equal 2.
i let you some caps for you understanding.
thank u.
best regards.
A 1x2 vector (x,y) will have a length of 2 since the length is the length of the longest dimension. You should use size():
[rows, columns] = size(ps1)
By the way did you see my explanation below?
this works perfectly, thanks a lot.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Productos

Versión

R2020a

Preguntada:

el 21 de Jun. de 2022

Comentada:

el 21 de Jun. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by