How can I resolve this problem using vertcat on matrices for daily files to create a single matrix for the whole year?

조회 수: 2 (최근 30일)
Hello,
I am trying to create a single matrix that represents soil moisture data for an entire year. I have one file from each day that is 96x25 and is in a .dat format. I have been trying to upload the files and then concatenating them using the vertcat function but every time I get the error "??? Error using ==> vertcat The following error occurred converting from double to struct: Error using ==> struct Conversion to struct from double is not possible."
I don't understand what the problem is because I'm not trying to convert to struct but I'm guessing that this might be part of the vertcat function? I have found multiple entries discussing similar problems but none that have helped in resolving my problem. I have included part of the prompt I'm using below. Thanks for any help you can give.
Tyler
datfiles=dir('*.dat');
numfiles=length(datfiles);
%Import the files
for k=1:length(datfiles);
newData1 = importdata(datfiles(k).name);
newData2 = importdata(datfiles(k+1).name);
A = newData1; %Create matrix A, with all data from the file
B = newData2;
C = [A; B]; %vertically concatenates matrix A to B
end if true
% code
end

답변 (2개)

Thorsten
Thorsten 2013년 2월 12일
편집: Thorsten 2013년 2월 12일
importdata returns a structure, not a matrix;
whos newData1

Kye Taylor
Kye Taylor 2013년 2월 12일
편집: Kye Taylor 2013년 2월 12일
So, I'm guessing that newData2 is not a structure, in particular it is a double?
Perhaps try fixing your code by replacing the line that defines A with
A = newData1.data;
  댓글 수: 2
Daniel
Daniel 2013년 2월 12일
편집: Daniel 2013년 2월 12일
I tried replacing this line and it gave an error saying 'attempt to reference field of non-structure array'. I was under the impression that the files were all in double after being imported, but am somewhat confused by this aspect. Sorry I can't give more information but I'm somewhat new to matlab. Let me know if I can give more details to help explain.
Each file is essentially the same, except for the second column which reflects the day of year (DOY). All I want is for it to start at DOY 1 and add each consecutive day's file until it reaches DOY 365. The desired result is a single file with all of this data in order.

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by