Matlab-Excel shape PROBLEM
이전 댓글 표시
Buongiorno, ho un file di testo che mi riporta una serie di dati in matrice e lo devo convertire in excel.
Il problema però non è questo, perchè lo so fare, ma il fatto è che devo mettere la matrice disposta in un determinato modo.
Ad esempio le primo 19 colonne le devo mettere tutte sulla stessa riga, e così dalla 20 alla 29 colonna ecc..
La mia matrice ha più di 1000 colonne!
Come posso fare?
Goodmorning I have a text file that gives me a serie of datas in matrix and I have to convert it in excel.
But that's not the problem, I can do that easily!
THe problem is that I have to shape the matrix in a different way, infact I have to take the first 19 columns and put them on the same row. And I have to do that with the columns from 20 to 29.
I have more than 1000 columns, how can I do that? Please!!
댓글 수: 5
Walter Roberson
2023년 10월 30일
So the first row should have 19 columns and the second row should have 10 columns? How many columns should the other rows have?
MATLAB arrays cannot have a different number of columns but if you put NaN in a location it show up empty in excel
Dyuman Joshi
2023년 10월 30일
Could be a typo, which is what I assumed (I know I should not have).
Nonetheless, OP has not replied yet given the "urgency" of their question.
Roberta Di Napoli
2023년 10월 30일
Roberta Di Napoli
2023년 10월 30일
Walter Roberson
2023년 10월 31일
What is the format of the txt file?
답변 (1개)
Walter Roberson
2023년 10월 30일
Create a vector containing the number of consecutive elements needed to move into each row. Not the indices, the count. So for example counts = [19 10 ... whatever] then
largest_split = max(counts);
total_wanted = sum(counts);
Column_to_Extract = 1;
splits = mat2cell(YourData(1:totalwanted,Column_to_Extract), counts, 1);
Block = cell2mat(cellfun(@(V) [reshape(V, 1, []), nan(1, largest_split-numel(V))], splits(:), 'uniform', 0));
Now if I did everything properly, Block should end up as a numeric array in which groups of consecutive rows in YourData have been converted into one row per group, and each row will be padded out with NaN to the length of the longest row.
If you now write that data out to an excel file, such as with writematrix() then the NaN will be converted to empty cells.
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!