concatenate structs and then plot a specified column

1 visualización (últimos 30 días)
Gaetano Pavone
Gaetano Pavone el 15 de Oct. de 2019
Abierta de nuevo: Adam Danz el 22 de Ag. de 2021
I have the following folder, named Dati_Finali:
folder.JPG
Each mat file contains a single variable named dati_finali, see the following figure, with different number of rows but equal number of columns:
cell.JPG
I would like to concatenate all the dati_finali cells vertically and then plot a specified column.
How can I do this? Thanks

Respuestas (1)

Adam Danz
Adam Danz el 15 de Oct. de 2019
Editada: Adam Danz el 15 de Oct. de 2019
Use dir() to list all files in the directory.
Loop through each file and load in the variable using load(filename,variables)
From within your loop you can vertically concatenate like so
C = [];
for i = 1:numberOfFiles
vars = load('filename','dati_finali')
C = [C;vars.dati_finali];
% ^ vertical concatenation
end
Then plot colun number 'n' by
plot(C(:,n))
If you have trouble putting any of this together, feel free to comment below and include the code.
  6 comentarios
Gaetano Pavone
Gaetano Pavone el 15 de Oct. de 2019
Editada: Gaetano Pavone el 15 de Oct. de 2019
I want to delete the first row of the uploaded matrices, except for the first one. If i use your code all first rows will be eliminated.
Moreover, plot of the 16th column is:
heights=C(:,16);
plot(cell2mat(heights(:,1)))
Adam Danz
Adam Danz el 15 de Oct. de 2019
Editada: Adam Danz el 16 de Oct. de 2019
"I want to delete the first row of the uploaded matrices, except for the first one. "
That's what conditional statements are for.
for i=3:4
vars = load(file(i).name,'dati_finali')
if i==3 % <--3 because your i-loop starts with 3
Cnew = vars.dati_finali;
else
Cnew = vars.dati_finali(2:end,:);
end
C = [C; Cnew];
end
About your cell array, what's stored in that array? Are they all numbers or is there a mix of numbers and strings/characters or other stuff? The solution for plotting the n_th column will depend on what's in those arrays.

Iniciar sesión para comentar.

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by