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
per isakson
2022년 6월 21일
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.
채택된 답변
추가 답변 (1개)
Karan Kannoujiya
2022년 6월 21일
0 개 추천
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
Erick Guzman
2022년 6월 21일
If element is a string array
str = ["abc","xyz",""];
find( strlength( str ) == 0 )
strlength( str(1,3) ) == 0
Erick Guzman
2022년 6월 21일
Image Analyst
2022년 6월 21일
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?
Erick Guzman
2022년 6월 21일
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!