how to convert the entries of a structure from single to double?

4 vues (au cours des 30 derniers jours)
David Pesetsky
David Pesetsky le 21 Mar 2019
Commenté : yonatan s le 31 Déc 2019
Hello,
I have a big structure. First column is numbers, but other columns (each cell of the column) are each a vector. Those vectors show as single, I want to convert them all to double. There are almost 300 of those vector-cells.
Can you help there?
  1 commentaire
Walter Roberson
Walter Roberson le 21 Mar 2019
Do you mean that you have a struct? Or you have a cell array?

Connectez-vous pour commenter.

Réponses (2)

Walter Roberson
Walter Roberson le 21 Mar 2019
new_cell_array = cellfun(@double, existing_cell_array, 'uniform', 0);
  4 commentaires
Walter Roberson
Walter Roberson le 21 Mar 2019
I do not understand what you mean by "column" with respect to a struct ? You have a structure array, and a column of a structure array would be like YourStructure(:, 3) for column three, giving a scalar struct (since you only have one row), but a struct itself cannot be numeric type.
Are you talking about fields? That fields number 2, 3, 4, 5, 6, 7 show up as single ?
Would it be acceptable to convert all of the fields to double, or are there some non-numeric fields?
yonatan s
yonatan s le 31 Déc 2019
to fix Error using cellfun Input #2 expected to be a cell array, was struct instead, try:
new_cell_array = structfun(@double, existing_cell_array, 'uniform', 0);

Connectez-vous pour commenter.


David Pesetsky
David Pesetsky le 21 Mar 2019
For each of the 6 columns that are vectors, this works:
for i=1:50
tmp_serie(i).Fedge = cast(tmp_serie(i).Fedge, 'double');
end
I'm all set.

Catégories

En savoir plus sur Data Type Conversion 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!

Translated by