How to I get required data out of categorical sets?

2 次查看(过去 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.

采纳的回答

Walter Roberson
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 个)

类别

Help CenterFile Exchange 中查找有关 Standard File Formats 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by