QEx
QEx

Reputation: 81

Passing Struct elements of variable lengths into a matrix Matlab

I am parshing a few data via the internet. The struct Data has several elements. I am interested in Data.Value a call of Data(1,1).Value is a double vector of [56,1]. Moving on to the second struct cell Data(1,2).Value is a double vector [46,1].

Writing a FOR Loop to get the entire Data(1,i).Value from 1 to 500, when it come to the second element, I get the following error returned: Subscripted assignment dimension mismatch.

Although I understand the error I cannot justify it and hence I cannot work out a solution.

I have also tried to pre-define a matrix of variable sizes to overcome this, without result.

Anybody can think of any solution to get the entire Data(1,:).Value

Thanks a lot for the contribution guys.

Upvotes: 1

Views: 112

Answers (1)

Mohsen Nosratinia
Mohsen Nosratinia

Reputation: 9864

You can use

vertcat(Data(1,:).Value)

to create a column vector made by concatenating Data(1,1).Value, Data(1,2).Value, ... Alternatively, you can use the generalized concatenation operator

cat(1, Data(1,:).Value)

Upvotes: 2

Related Questions