Filter löschen
Filter löschen

converting this LIBSVM data to a normal matrix?

3 Ansichten (letzte 30 Tage)
Desiree
Desiree am 24 Apr. 2020
Kommentiert: Shishir Singhal am 30 Apr. 2020
Hello,
I need to convert this LIBSVM data in form of struct with 2 fields to a normal matrix 8192x12.
I've found this here online:
function y=svm2mat(s)
% Usage: y=svm2mat ('filename')
clc
fid = fopen(s);
i=1;
while ~feof(fid) % not end of the file
s = fgetl(fid); % get a line
s1=[]; j=1;
while (j<=length(s))
while ( s(j)~=' ') && (j<length(s))
s1=[s1 s(j)];
j=j+1;
end
j=j+1;
s1=[s1 ' '];
while ( (j<length(s)) && (s(j)~=':') )
j=j+1;
end
j=j+1;
end
s2=str2num(s1) ;
if (i==1)
yy=zeros(1,length(s2));
end
yy=[yy,s2];
i=i+1;
end
yy(1,:)=[];
y=yy;
but it doesn't work for me.
Help is greatly appreciated!
  1 Kommentar
Shishir Singhal
Shishir Singhal am 30 Apr. 2020
Could you please state the error related to this solution ?

Melden Sie sich an, um zu kommentieren.

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