fill array with null if index is empty

조회 수: 6 (최근 30일)
Saud Alfalasi
Saud Alfalasi 2021년 2월 20일
답변: Mahesh Taparia 2021년 2월 23일
R = string(data{:});
for ii=1:27
text_str{ii} = convertStringsToChars(R(ii));
Hi, how would I set elements to "nil" if elemenet at that index doesn't exist?
eg:
apple
pear
nil
nil
Bannana
nil
....all the way to index 27

답변 (1개)

Mahesh Taparia
Mahesh Taparia 2021년 2월 23일
Hi
You can check for a particular index, if the array content of that index is empty then you can assign it to "nil". For example, consider the code below:
for i=1:N
if(ismissing(R(i)))
R(i)={"Nil"};
else
continue;
end
end
Hope it will help!

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by