eliminating, whenever is necessary the first column in nun where [num,txt,r​aw]=xlsrea​d('data.xl​sx');

1 vue (au cours des 30 derniers jours)
Dear all, I am struggling to find a solution to the following problem. I load many excel files Say for instance that I load the following file
[num,txt,raw]=xlsread('data.xlsx');
The problem is that sometimes the first column of the “raw” matix, which normally contains this type of information
[ NaN]
[ NaN]
[ NaN]
[ NaN]
[ NaN]
[ NaN]
[ NaN]
' YEs'
'NO'
Contains also numbers in some cells. For example
[ NaN]
[ NaN]
[ NaN]
[ NaN]
[ NaN]
[ NaN]
[ NaN]
' YEs'
'NO'
[ 0]
As a result of this situation, the matrix “num” , creates a first column which is useless as it contain no information(it contains only NaN and zeros). If the first column of the “raw” matrix contains no numbers then such useless column does not appear in “num”
My goal was to develop a code that could identify this problem and eliminate, whenever is needed, the first useless column from “num”
So far I have made no progress
thanks
  2 commentaires
Sabbas
Sabbas le 2 Juil 2012
Modifié(e) : Sabbas le 2 Juil 2012
I have an idea. The first column of “num” will be useless is it contains ONLY NaNs AND zeros
So I am looking for something like
if isnan(num(:,1)) & num(:,1) contains zeros
num(:,1)=[]
end
I have some difficulty, though , with the expression
if isnan(num(:,1)) & num(:,1) contains zeros
thanks
Walter Roberson
Walter Roberson le 3 Juil 2012
xlsread() will treat top-most rows or left-most columns as being headers if it thinks the columns are text.

Connectez-vous pour commenter.

Réponse acceptée

Kye Taylor
Kye Taylor le 3 Juil 2012
I like your approach.
try
if all (isnan(num(:,1)) | num(:,1) == 0)
num(:,1) = [];
end
note that there may still be some NaNs in the first column. To remove the first column whenever any nan is present, try
if any(isnan(:,1))
num(:,1) = [];
end

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by