reshaping and the size of an array
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi!
I have this statement in a program
% mag=reshape(mag,length(mag)/27,[]);
the size of mag is now 120*27
when i make this statement to clear nan values : (ids is an index of a condition!!!)
mag(ids)=nan;
mag=mag(~isnan(magg));
i get a size of m*1. (the length m is smaller than the number 120*27) why does the size of may matrix mag change when i use mag=mag(~isnan(magg))?
how could i get the n*27 (the length n is smaller than the number 120)
thank you
Hi It was my mistake the statement is: magg=mag,mag=mag(~isnan(mag))
i hope you could help me!
0 commentaires
Réponse acceptée
Jan
le 16 Nov 2012
Modifié(e) : Jan
le 16 Nov 2012
You do not post the contents of magg, but obviously it has less non-NaN elements than 120x27. Do you mean mag with one "g"?
If you remove NaN elements from an array, the array get smaller. This is evident, isn't it? And when elements disappear, it is impossible to guarantee, that the remaining number of elements allows to build an rectangular matrix with the same number of elements for all columns and the same for all rows. Therefore Matlab replies a vector for logical indexing.
Simply try it:
A = [NaN, 1; 2, 3]
A = A(~isnan(A))
What else instead of a [3 x 1] vector could be replied?
If you want to remove all rows, which contain any NaN:
index = all(~isnan(A), 2);
A = A(index, :);
Now keeping the same number of elements per row can and does work.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!