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

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?

Answers (2)

new_cell_array = cellfun(@double, existing_cell_array, 'uniform', 0);

4 Comments

I get:
Error using cellfun
Input #2 expected to be a cell array, was struct instead.
It's a 1x50 struc
Inside it, the first column is just numbers.
But in each entry of the next 6 columns they all show as 16385x1 single. So I suppose each of those are a vector? And the file that works says each should be a 16385x1 double. So I'm just trying to change the type of those 300 vector entries to double.
So I was able to pull one of the Single vectors out like this:
tmp_serie(48).Faxial
Which gives the 16385 values of single precision.
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?
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);

Sign in to comment.

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.

Categories

Asked:

on 21 Mar 2019

Commented:

on 31 Dec 2019

Community Treasure Hunt

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

Start Hunting!