Convert struct to matrix MATLAB

matlab struct to double
matlab struct2mat
cell to matrix - matlab
convert struct to string matlab
matlab convert structure to string array
matlab convert structure fields to variables
struct to vector? - matlab
matlab extract data from structure

Is there a way to convert a struct (2 fields with 52 variables each) to a matrix (2x52)? Thank you

struct:

    sym (1x53)
    prob (1x53)

I have tried the following which gives me a 1 x 1 cell array

symProb = reshape({x.sym}, size(53)); 

I have also tried struct2cell which does the same.

Probably the easiest thing (since it's only two fields), is to simply concatenate them along the first dimension using cat

result = cat(1, x.sym, x.prob);

Or you could just use [] and ;

result = [x.sym; x.prob]

If you want a more general solution, you could use struct2array with some reshaping

result = reshape(struct2array(x), [], numel(x)).';

Note that all of this assumes that the data within sym and prob are actually the same datatype and therefore able to be placed within the same array, otherwise a cell array is the only way to hold both fields.

Also your code is yielding a 1 x 1 cell array because you're wrapping your data x.sym inside of a 1 x 1 cell array.

how to convert structure array into matrix, I assume the fields of your structure, 's' are cell arrays and that all of the cell arrays have the same size and are row vectors. If the fields are  For a fixed-size array of structures S, if struct2cell cannot convert S to a homogeneous cell array, then the output cell array is heterogeneous. A heterogeneous output cell array can have a maximum of 1024 elements.

An alternative approach is as follows:

symVec = [x.sym(:)]
probVec = [x.prob(:)

how i can convert struct to matrix - MATLAB Answers, Hello Dear Matlab users,. Is there any way to convert str to matrix form? I want to get all values of different fields with its subvalues. ho can i convert a structure to a matrix?. Learn more about converting structure to matrix

You can use this:

cell2mat(struct2cell(YourStructure))

How can I convert struct to mat - MATLAB Answers, by struct to mat do you mean structure array to a matrix? If then all the fields should only be numeric. Or do you mean cell array? mat something  convert the field of a struct in a matrix. Learn more about matrix, struct . Because basically you are saying that beginners are unable to understand MATLAB

Convert structure to cell array - MATLAB struct2cell, Probably the easiest thing (since it's only two fields), is to simply concatenate them along the first dimension using cat result = cat(1, x.sym,  I assume the fields of your structure, 's' are cell arrays and that all of the cell arrays have the same size and are row vectors. If the fields are column vectors, some tiny adjustments will be needed.

Convert struct to matrix MATLAB, I have a 1x10,000 struct (annotatedeventdata) with 2 fields, one being an event number and the other being a 16x499x4 matrix (raw data). I want to convert this  Convert matrix to vector of structs. Learn more about vector, structures, struct, structure, vectors, vectorizing

Trying to convert struct to matrix : matlab, struct2cell. Convert structure to cell array. Syntax. c = struct2cell(s). Description. c = struct2cell(s) converts the m -by- n structure s (with p fields) into a p -by- m  by struct to mat do you mean structure array to a matrix? If then all the fields should only be numeric. Or do you mean cell array? mat something totally different.

Comments
  • Can you provide actual example of you struct with those variables?