Filter löschen
Filter löschen

How to convert a structure int16 into a matrix?

4 Ansichten (letzte 30 Tage)
maria
maria am 31 Aug. 2018
Bearbeitet: Stephen23 am 31 Aug. 2018
I am opening a variable (VAR) which is a structure and it contains inside 3 field which column of numbers (a,b,c) and 4th column (c) with a structure 700x4. I would like to work with c(:, 3), but by using the code
struct2array(VAR.C(:,3));
I obtain the error: Undefined function 'struct2cell' for input arguments of type 'int16' How to solve it?
str2double
also does not work...

Akzeptierte Antwort

Stephen23
Stephen23 am 31 Aug. 2018
Bearbeitet: Stephen23 am 31 Aug. 2018
You don't need to do anything extra, because this is already the numeric data that you want:
VAR.C(:,3)
VAR is a structure, so you could apply struct2cell to this, but there is no point for what you are doing. The field of a structure can be any class: numeric, cell, struct, function handle, ... In your case the field C is numeric, with class int16, so you don't need to apply any other functions to make it numeric... it already is numeric!
str2double would only make sense to apply if you have a character vectors, a string array, or a cell array of char vectors. You don't appear to have any of those in your data.
You should revise the basic data types, and how to access structure data:

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by