forked from minjiechen/PowerVision
-
Notifications
You must be signed in to change notification settings - Fork 0
/
machinelearning.m
68 lines (60 loc) · 2.09 KB
/
machinelearning.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
clear all,clc,close all
% netlist classifier
pwm_basic=loaddata('pwm-basic');
pwm_adv=loaddata('pwm-adv');
resonant=loaddata('resonant');
others=loaddata('others');
fulldata = [pwm_basic;pwm_adv;resonant;others];
function datacell = loaddata(path_directory)
original_files=dir([path_directory '/*.json']);
for k=1:length(original_files)
fname=[path_directory '/' original_files(k).name];
fid = fopen(fname);
raw = fread(fid,inf);
str = char(raw');
fclose(fid);
val = jsondecode(str);
ncomp = length(val);
nnode = length(val{1,1});
for i=1:ncomp
for j=1:nnode
row = val{i,1};
if j==1
icmatrix{i,j} = row{j,1};
else
icmatrix{i,j} = int8(str2num(row{j,1}));
end
end
end
newmatrix = zeros(16,16);
for i=1:ncomp
for j=2:nnode
if icmatrix{i,j} ~= 0
switch icmatrix{i,1}
case "X"
newmatrix(i,j-1)=20+icmatrix{i,j};
case "I"
newmatrix(i,j-1)=40+icmatrix{i,j};
case "V"
newmatrix(i,j-1)=60+icmatrix{i,j};
case "D"
newmatrix(i,j-1)=80+icmatrix{i,j};
case "L"
newmatrix(i,j-1)=100+icmatrix{i,j};
case "C"
newmatrix(i,j-1)=120+icmatrix{i,j};
case "R"
newmatrix(i,j-1)=140+icmatrix{i,j};
case "M"
newmatrix(i,j-1)=160+icmatrix{i,j};
end
end
end
end
newmatrix( ~any(newmatrix,2), : ) = []; %rows
newmatrix( :, ~any(newmatrix,1) ) = []; %columns
newmatrix(32,32) = 0;
datacell{k,1}=newmatrix;
datacell{k,2}=path_directory;
end
end