How to I get required data out of categorical sets?
1 回表示 (過去 30 日間)
古いコメントを表示
I have 49 asc files that are both of 1 and 0 type. 1 represents till and 0 represents no-till. I already get all the reflectance values on 49 files and also the till types? I am trying to the reflectance values out of each category. Reflectance are 49*9 cell where first two represents the latitude and longitude so I want to get 23*7 cell for notill type and 26*7 cell for till type. I only get 23*1 cell for notill instead of 23*7 cell. The following code is the code that I used:
startRow =2;
names = ls('*.asc');% providing the list of the files in the folder
formatSpec = '%s %s %s %s %s %s %s %s %s';
[num_files, ~]=size(names);
reflectance =[];
for n=1:num_files
fileID = fopen(names(n,:),'r'); %open file with read only permission
dataArray = textscan(fileID,formatSpec,'Headerlines', 5);
fclose(fileID);
reflectance = [reflectance; dataArray];
end
d=dir('*till.asc'); % all till/notill files
isTill=false(length(d),1); % preallocate logical of classification
for i=1:length(d)
fid=fopen(d(i).name,'r');
isTill(i)=isempty(strfind(d(i).name,'notill')); % logic variable
if isTill == 1
Till = reflectance(isTill);
else
notill = reflectance(isTill);
end
end
Let me know what I am missing. Thanks a lot for your time and help.
0 件のコメント
採用された回答
Walter Roberson
2016 年 9 月 27 日
In your loop
for i=1:length(d)
fid=fopen(d(i).name,'r');
isTill(i)=isempty(strfind(d(i).name,'notill')); % logic variable
if isTill == 1
Till = reflectance(isTill);
else
notill = reflectance(isTill);
end
end
You are overwriting all of Till or all of notill for each i .
Note: remember to fclose(fid)
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!