How do I take data from one column of an Excel spreadsheet and store it as a transposed row in a new Excel Spreadsheet? How do I repeatedly take this column data from different Excel spreadsheets to be transposed as rows in the new Excel Spreadsheet?
조회 수: 3 (최근 30일)
이전 댓글 표시
So I have a lot of .xlsx files (I have attached one here). I need to take the data from column 7 (Heart Rate), from a specific number of rows (in THIS case, from row 1944 till row 2730) and input this data in the form of a row in a new Excel spreadsheet. I need to repeat this process for the rest of my xlsx files and store their 7th columns into the same new Excel spreadsheet. Is there a way to automate this process, keeping in mind that these different .xlsx files may have a different number of rows to be stored?
Below is the code I've used to import one of my .xlsx files into MATLAB. I have also attached the respective .xlsx file.
[~,NumDataS]=xlsread('Oxygen_6.10.19_Dex_0024_vitals.xlsx','Sheet2','F1944:G2730'); % Physiological Data
[~,TmatrixS] = xlsread('Oxygen_6.10.19_Dex_0024_vitals.xlsx','Sheet2','A1944:F2730'); % Time Data
HR = cellfun(@str2double, NumDataS(:,2)); % Retrieve From Cell Array Of Strings
Time1=cellfun(@str2double, TmatrixS(:,5));%Array of minutes to be converted to seconds
댓글 수: 0
채택된 답변
Abhilash Padma
2019년 8월 12일
You can use the “writematrix” method to store a matrix in an excel spreadsheet. See the following code where this method is used.
[~,NumDataS]=xlsread('Oxygen_6.10.19_Dex_0024_vitals.xlsx','Sheet2','F1944:G2730'); % Physiological Data
[~,TmatrixS] = xlsread('Oxygen_6.10.19_Dex_0024_vitals.xlsx','Sheet2','A1944:F2730'); % Time Data
HR = cellfun(@str2double, NumDataS(:,2)); % Retrieve From Cell Array Of Strings
Time1=cellfun(@str2double, TmatrixS(:,5));%Array of minutes to be converted to seconds
writematrix(Time1','sample.xlsx','Range','A1');
If you want to store columns of different excel spreadsheets, consider a cell array which contains each cell as a filename. Then, put all the above statements in a loop. For example:
files={'Oxygen_6.10.19_Dex_0024_vitals.xlsx','example.xlsx',……………….};
row='A1';
for i=1:length(files)
[~,NumDataS]=xlsread(files{i},'Sheet2','F1944:G2730');
....
writematrix(Time1','sample.xlsx','Range',row);
row(2)=row(2)+1;
end
For more information, refer the following link: https://www.mathworks.com/help/matlab/ref/writematrix.html
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!