How to delete rows from a matrix array ?

I have a 1x8 matrix named waterConductivityData. Each column has 5 rows.
For example, waterConductivityData{1,3} contains the following string data:
's'
'd'
'2012-03-26 00:00'
'2012-03-26 01:00'
'2012-03-26 02:00'
and waterConductivityData{1,7} contains the following double data:
14
0
327
329
330
I wrote the following code to go through {1,3} and delete the cells that do not contain date data. (in other words, delete cells one and two)
waterConductivityData{1,3}(cellfun('length',waterConductivityData{1,3})==1) = [];
the output deleted the first two rows which was exactly what I needed:
waterConductivityData{1,3} = '2012-03-26 00:00' '2012-03-26 01:00' '2012-03-26 02:00'
I want to delete the same rows (rows one and two) from waterConductivityData{1,7}
I tried:
waterConductivityData{1,7}(cellfun('length',waterConductivityData{1,3})==1) = [];
but this does not work.
Basically, whatever rows are deleted from waterConductivityData{1,3} I need to have delted from waterConductivityData{1,7} also.
Can someone help please?

Réponses (2)

Andrei Bobrov
Andrei Bobrov le 21 Juil 2013
Modifié(e) : Andrei Bobrov le 22 Juil 2013
t = ~cellfun('isempty',waterConductivityData);
d = waterConductivityData{3};
ii = cellfun(@(x)numel(x)> 8,regexp(d,'\d'));
out = cellfun(@(x)x(ii),waterConductivityData(t),'un',0)

2 commentaires

Jan
Jan le 21 Juil 2013
Modifié(e) : Jan le 21 Juil 2013
"~isempty(x) & numel(x)> 8" looks redundant.
Andrei Bobrov
Andrei Bobrov le 22 Juil 2013
Hi Jan! I agree with you, corrected. Thanks.

Connectez-vous pour commenter.

John August
John August le 21 Juil 2013
I figured out what my problem was and it was a stupid issue.
Let me explain. This was the order of my code:
waterConductivityData{1,3}(cellfun('length',waterConductivityData{1,3})==1) = [];
waterConductivityData{1,7}(cellfun('length',waterConductivityData{1,3})==1) = [];
You can see that I was deleting the first two rows of waterConductivityData{1,3} then using that corrected data to try and delete the first two rows of waterConductivityData{1,7}.
But I already had corrected waterConductivityData{1,3} so It made no sense.
The solution was to switch my code:
waterConductivityData{1,7}(cellfun('length',waterConductivityData{1,3})==1) = [];
waterConductivityData{1,3}(cellfun('length',waterConductivityData{1,3})==1) = [];
I'm sure my explination was a little hard to understand.... but it works now.
I really appreciate your help! Thank you.

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by