Can someone help me. What I need to do if I want to convert a struct array to double or complex double to double because i need to use it as input for svm classifier.Thanks in advanced .
Asked
Active
Viewed 672 times
-3
-
Please show us your code so far... – Paulo Mattos Apr 19 '17 at 03:11
-
i already combined 7 patients that contain 19 feature extraction each one.. the data in 7x1 struct with 19 field ..when i using in SVM clc;clear all;close all; load trainset.mat data =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. i know that i need to convert the struct array into double but dont know how? can u help me – Aida Ezati Apr 19 '17 at 03:23
-
1It's much more helpful if you add your code to the initial question with proper formatting. Reading it out of the comments is...difficult. It would probably also help to see a small extract of the structure that's causing the error. – user2027202827 Apr 19 '17 at 07:35
1 Answers
0
Assuming your data struct looks like this (with 7 patients, 19 features and 150 feature vectors for each patient):
data =
p1: [150x19 double]
p2: [150x19 double]
p3: [150x19 double]
p4: [150x19 double]
p5: [150x19 double]
p6: [150x19 double]
p7: [150x19 double]
and you want to concatenate them into one big matrix (you will not distinguish between patients when training your SVM) of the form 1050x19 double
, then the following code snippet will do the trick:
% Generate test data
data.p1(:,1:19) = randn(150,19);
data.p2(:,1:19) = randn(150,19);
data.p3(:,1:19) = randn(150,19);
data.p4(:,1:19) = randn(150,19);
data.p5(:,1:19) = randn(150,19);
data.p6(:,1:19) = randn(150,19);
data.p7(:,1:19) = randn(150,19);
% Add each patient features to cell array
data_cell = cellfun(@(field) data.(field), fieldnames(data), 'UniformOutput', false);
% Vertically concatenate the entries in the cell array from above
data_combined = vertcat(data_cell{:}); %1050x19 double
You will need to concatenate your group
labels in a similar way as well, making sure you don't loose track of which group label corresponds to which feature vector in your combined data.
Best of luck
-
thanks but what is feature vector? I have 7x1 struct with 19 field , which one i should assume as feature vector? – Aida Ezati Apr 20 '17 at 01:35