How to export variables in mat file to excel?

4 visualizaciones (últimos 30 días)
Yuqing
Yuqing el 19 de Dic. de 2013
Respondida: Image Analyst el 20 de Dic. de 2013
I have a lot of data to deal with. I have saved different variables in a structure data. for example:
HistStruct:
velocity < 12441x1 double >
median 0.1449
mean 0.1552
and I save them into mat file. I have nearly 100 HistStruct.mat files. Now I want to calculate the average value of each of them. But I dont know how to export them from variables edit. Can anyone help me? Thank you very much.
  3 comentarios
Yuqing
Yuqing el 19 de Dic. de 2013
Thank you for your answer. I am a beginner. I really feel confused now. I save the values of velocity, median, mean in to the fields of HistStruct. Histstruct.velocity= < 12441x1 double > %there are 12441 values Histstruct.median=0.12 Histstruct.mean= 0.13 I save these variables into mat file named Histstruct.mat. Now I have many files called Histstruct.mat. I wanted to combine all the values of velocity together from Histstruct.velocity of different HistStruct.mat files into one mat file.
Thank you very much for your help.
Amit
Amit el 20 de Dic. de 2013
First - are all the files are named Histstruct.mat? It they are, they must be stored in different folders? Unless there is some structure in storage of these files, I dont see how you can get away from manually loading each file. The idea would be creating a matrix (lets call A) (if you preallocate the matrix, that would be better). After loading first Histstruct.mat, do something like
A(1:numel(Histstruct.velocity)) = Histstruct.velocity;
After the first time and loading more Histstruct.mat do this;
A(end+1:end+numel(Histstruct.velocity)) = Histstruct.velocity;
And In the end, simple mean command on A will give you the results.

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 20 de Dic. de 2013
How about if you attach histstruct.mat? Basically you don't import a mat file to Excel. It's more of a two or three step process. You load it into MATLAB first, and then export it from MATLAB to Excel with xlswrite().
To load it into MATLAB first, you have to read in all your mat files and build up a big cell array to contain all the data. The FAQ will be helpful for that: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
Then you write the cell array to Excel in a single call to xlswrite() after your loop exits.

Más respuestas (1)

Amit
Amit el 19 de Dic. de 2013
I think you are trying to get average value for velocity. If that's correct simply use
mean(HistStruct.velocity)
This will give you the average.

Categorías

Más información sobre Workspace Variables and MAT Files en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by