reading adding array of same size

조회 수: 1 (최근 30일)
Uday
Uday 2011년 10월 21일
I have some dataset in which I can get values of latitude longitude ch4
in this data I do not have year but I know the year of file.
path=('/Temp/test/'); dir_list=dir('v41_CH4*.txt');
vec1=[];
for i=1:length(dir_list)
data=dlmread(dir_list(i).name,';',3);
latitude=data(:,1);
longitude=data(:,2);
ch4=data(:,3);
vec1=[vec1;ch4];
end
in above code I am getting vec1 with all values in whole data set and I would like get one array of year also so I can plot time series of this data. e.g in data I have 2 files 1970, 1975 how to get this out put output=[vec1 year]

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 10월 21일
If it is year per file, you can do:
ch4=data(:,3);
YearData=Year*ones(size(ch4)); %Year is whatever info you can get
vec1=[vec1;ch4,YearData];
  댓글 수: 2
Uday
Uday 2011년 10월 21일
hi it works but I am not getting the out put what I want. It just shows me one common out put;
path=('/Temp/test/');
dir_list=dir('v41_CH4*.txt');
vec1=[];
year=[1970,1975];
for i=1:length(dir_list)
data=dlmread(dir_list(i).name,';',3);
latitude=data(:,1);
longitude=data(:,2);
ch4=data(:,3);
YearData=year(i)*ones(size(ch4));
vec1=[vec1;ch4,YearData];
end
e.g one file is for 1970 and another one is for 1975 , but in output I am getting only 1975.
How to solve this problem?
Thanks
Fangjun Jiang
Fangjun Jiang 2011년 10월 21일
If you have just two files, your above code should work. Run your code step by step to debug. Maybe your first file doesn't contain data?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by