-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreaddataWOReClass.m
68 lines (65 loc) · 1.66 KB
/
readdataWOReClass.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
%'C:\Users\Administrator\Desktop\newfile2\extract1re.txt'
%dlmread('C:\Users\Administrator\Desktop\newfile2\extract2re.txt','\t',6,0);
function datam = readdataWOReClass(path)
fid1 = fopen(path);
i=1;
ncols =10;
nrows = 10;
while ~feof(fid1)
aline=fgetl(fid1);
splitstr = regexp(aline,' ', 'split');
len = length(splitstr);
if len <100
if strcmp(splitstr(1),'ncols')
ncols = str2double(splitstr(end));
elseif strcmp(splitstr(1),'nrows')
nrows = str2double(splitstr(end));
end
datam = zeros(nrows,ncols);
datam(:) = -9999;
else
break
end
end
while ~feof(fid1)
aline=fgetl(fid1);
splitstr = regexp(aline,' ', 'split');
len = length(splitstr);
if len>100
%sum(~~str2double(splitstr(1:l)))
l = ncols;
linedata = str2double(splitstr(1:l));
datam(i,:) = linedata;
i=i+1;
end
end
fclose(fid1);
n2 = length(unique(datam));
uni2 = unique(datam);
for i = 1:n2
uni2(i)
length(find(datam==uni2(i)))
if(uni2(i)==1)
%farmland
datam((datam==uni2(i)))=14;
elseif(uni2(i)==2)
%forest
datam((datam==uni2(i)))=42;%5.5;
elseif(uni2(i)==3)
%River
datam((datam==uni2(i)))=33;%26;
elseif(uni2(i)==4)
%Grass Land
datam((datam==uni2(i)))=33;
elseif(uni2(i)==5)
%Urban land
datam((datam==uni2(i)))=42;
elseif(uni2(i)==6)
%Indus land
datam((datam==uni2(i)))=58;
elseif(uni2(i)<0)
%background color
datam((datam==uni2(i)))=0;
end
end
end