Turning separate columns of data into a single column or vector.
조회 수: 3 (최근 30일)
이전 댓글 표시
If I have a for loop looping through 12 files of data and I use the function A.data(:,1) in the loop to pull out the first column of each file, how do I turn those 12 columns into a single column. The first column in each file is the time column for the collected data; I want to string the time from each file together to make one long time vector with which I can make plots.
I will need to do this with every other column in the data aswell.
댓글 수: 2
Stephen23
2019년 5월 14일
The best solution is to follow the MATLAB documentation and use a cell array:
This will be more efficient than expanding an array in the loop, and will not give any warnings:
N = ... total number of files
C = cell(1,N);
for k = 1:N
C{k} = ... import one column of data
end
V = vertcat(C{:})
채택된 답변
Adam
2019년 5월 13일
times = [];
for ...
...
times = [ times; A.data(:,1) ];
...
end
You will get warnings about variable growing in a loop being slow, but if you are not able to presize them because you don't know how many rows there are in your files then you just have to ignore that. For 12 files it will likely be inconsequential anyway.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!