Find Empty Fields in Matrix and Delete them

10 ビュー (過去 30 日間)
Matpar
Matpar 2020 年 4 月 21 日
コメント済み: Rik 2020 年 4 月 21 日
Hi All,
I am trying to create a FOR LOOP that deletes all the empty field in my matrix!
I have some rows that are full of data and some that are empty and I would like to learn the formula to do such!
I want to learn this please!
can someone demonstrate an example, Please? I am uncertain of the terminology to express!
Thank you in advance!
  6 件のコメント
Matpar
Matpar 2020 年 4 月 21 日
I am trying to delete the rows that are [] empty or even better write a for loop that selects all of the data from the rows that has data within them!
Matpar
Matpar 2020 年 4 月 21 日
Hi Rik
All lines where at least one cell is empty, Please guide me? and thank you for the confirmation on the row arrays!!

サインインしてコメントする。

回答 (1 件)

Rik
Rik 2020 年 4 月 21 日
編集済み: Rik 2020 年 4 月 21 日
%generate fake data
data=cell(30,10);
for n=1:numel(data)
if rand>0.2
data{n}=rand(1,5);
end
end
%find all cells that don't contain data
L=cellfun('isempty',data);%faster than L=cellfun(@isempty,data);
%remove rows with any empty cell
emptyrows=any(L,2);
data(emptyrows,:)=[];
You can also use L to loop through the elements that have data in them (just invert it with the ~ operator).
  8 件のコメント
Matpar
Matpar 2020 年 4 月 21 日
編集済み: Matpar 2020 年 4 月 21 日
Thank you for breaking down my confidence RIK!
this may come easy for you but nevertheless the 60 odd questions they were posted becasue of wanting a better method or being confused to the point of giving up!
Sorry for displying the ID10T error!! I will try the documentations next time, I think I will stop coding for the week
Rik
Rik 2020 年 4 月 21 日
I didn't mean to insult you. I meant exactly what I said: I don't see how they would be easier to understand than the oneliner. And the Matlab documentation is an excellent resource, so you will be missing out massively if you don't learn to use it. Nobody is born knowing this, everyone who knows it was taught this at some point.
If you have trouble understanding the documentation I would be happy to explain it to you. I only wanted to direct you to it because if you learn how to help yourself it would save you waiting for a reply from me or someone else.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by