-1

I have combined 7 patients' data, each containing 19 features, into one struct as seen below. The data is now in a 7x1 struct with 19 fields.

enter image description here

What do I need to do to convert the struct to a double array? I need to use it as input for an SVM classifier. Or any suggestions for how to save the patients' data directly into a double array not a struct.

enter image description here

Aida Ezati
  • 21
  • 7
  • when i using in SVM clc; clear all; close all; load trainset.mat d ata =new_var; group = label; SVMStruct = svmtrain(data,group,'kernel_function','linear'); species = svmclassify(SVMStruct,meas,'showplot',false); the error will be "Error using svmtrain (line 241) TRAINING must be a numeric matrix". – Aida Ezati Apr 19 '17 at 04:50

1 Answers1

1

use struct2array:

% generating struct
dataStruct = struct;
[dataStruct(1:5).a] = deal(rand,rand,rand,rand,rand);
[dataStruct(1:5).b] = deal(rand,rand,rand,rand,rand);
[dataStruct(1:5).c] = deal(rand,rand,rand,rand,rand);
% convert it to matrix
data = reshape(struct2array(dataStruct),[],numel(dataStruct))';
user2999345
  • 4,195
  • 1
  • 13
  • 20
  • can i know which one input,which one output? because error state that "Error using deal (line 37) The number of outputs should match the number of inputs." I change 5 into 7 and copy''[dataStruct(1:5).c] = deal(rand,rand,rand,rand,rand);'' for 19 times because the data in 7x1 struct with 19 field ..if correct why i get error? – Aida Ezati Apr 19 '17 at 06:59
  • already solved..thank you – Aida Ezati Apr 19 '17 at 07:12
  • you don't need the first part, it's just for me to generate an example struct (as you already have). use just the last line. – user2999345 Apr 19 '17 at 07:44
  • sorry..but why value after change into double always changing each time i try with the same image? – Aida Ezati Apr 20 '17 at 01:13
  • because the lines constructing the structure in my code generate **random** data in the struct – user2999345 Apr 20 '17 at 05:25
  • sorry but i don't understand what it is..but if you can help me..what should i do if i want the the data obtained each time of the converting with the same value for same picture. because I want save this data in database for my support vector machine then as input..thank in advance – Aida Ezati Apr 20 '17 at 13:10
  • ignore my answer, just do `data = reshape(struct2array(dataStruct),[],numel(dataStruct))';` where `dataStruct` is your struct name. – user2999345 Apr 20 '17 at 13:19
  • sorry to disturb you again ,, but the struct convert into 19x1 complex uint8 – Aida Ezati Apr 20 '17 at 13:36