필터 지우기
필터 지우기

How to I get required data out of categorical sets?

조회 수: 2 (최근 30일)
Sonisa
Sonisa 2016년 9월 27일
댓글: Sonisa 2016년 9월 27일
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