Borrar filtros
Borrar filtros

Matlab-Excel shape PROBLEM

1 visualización (últimos 30 días)
Roberta Di Napoli
Roberta Di Napoli el 30 de Oct. de 2023
Comentada: Walter Roberson el 31 de Oct. de 2023
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 comentarios
Roberta Di Napoli
Roberta Di Napoli el 30 de Oct. de 2023
I am taking the datas from a .txt Also I was thinking of using a for function. I don't know. I'm welcome to any advise. Thank you for the help!
Walter Roberson
Walter Roberson el 31 de Oct. de 2023
What is the format of the txt file?

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 30 de Oct. de 2023
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.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by