How to I get required data out of categorical sets?

1 view (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 27 Sep 2016
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)

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!