필터 지우기
필터 지우기

loop

조회 수: 1 (최근 30일)
ricco
ricco 2011년 11월 10일
I have a script which reads .dat files into matlab. I have written the script to work for any year, as in the specific year that you type in the beginning. I am just wondering how to change to code so that I can use it for more than one year of data, my code is:
files = dir('*.dat');
Year=input('year:');%which i use 2007
%use the number of files to run a loop to import the relevant data
for i=1:length(files);
File_Name{i}=files(i,1).name;%Removes the file names from 'files'
data{i}=importdata(File_Name{i});%import the data selected by the file
%names given in 'File_Name'.
data{i}=data{i}(1:2:end,:);%this takes every other row of data(i),
%starting with the first.
data{i}=data{i}(:,2:end);%this just re-defines the matrix so that
%every row is kept and every column from the second onwards.
%CONVERT DATA INTO ONE MATRIX
data1=cell2mat(data');
%categorise the data so that we have one variable defining each year
Y_data=find(data1(:,1) == Year);
Y_data=data1(Y_data,:);
end
So, at the minute Y_data is a matrix for the data from 2007. I want Y_data to give me 3 matrices, one for 2007, one for 2008, and the other for 2009. I want to know how it would be possible to say in the beginning that Year can be equal to more than one year so that during the end of the loop you can create more than one matrix, if that makes sense.
cheers

답변 (1개)

ricco
ricco 2011년 11월 10일
failing this, how is it possible to use mat2cell but define which values I want in each cell. The matrix I have has the first column for year so how would I use mat2cell to have a cell which made up of three different years; i.e. im guessing first find the values in the matrix corresponding to each year and then place those values in different cells?
cheers
  댓글 수: 1
Fangjun Jiang
Fangjun Jiang 2011년 11월 10일
help mat2cell

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by