Borrar filtros
Borrar filtros

Build a matrix from saved arrays with differents lengths

1 visualización (últimos 30 días)
Hi to all!
I'm working on a simulation program. Each time the programs ends a simulation it saves the data (an array sized of 1 row and multiple columns) to a single .mat file: 'rf_ln1.mat'
For each simulation array size can change.
So, now: How can I construct a matrix from this saved different sized arrays? Because I don't know the size of each saved line unless I load them.
For example: rf_ln1.mat, rf_ln2.mat... rf_ln129.mat M = [rf_ln1.mat rf_ln2.mat ... rf_ln129.mat];
1. Is there an easy way such as using a struc or cell or a function? 2. Any tips? Ideas? Has someone already done this?
I would do: load file save it into a struc or cell (o create a variable with the name) seach the biggest one create a zero matrix sized (1,biggestone) create for each array a new one with the max size of all arrays insert it in the zero matrix
Any ideas with no so much steps?
Thanks for your answers! :)

Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de En. de 2012
You can use whos() with the -file option in order to find the matrix sizes without loading the files.
  2 comentarios
Daniel
Daniel el 23 de En. de 2012
Is there a form to get in a variable the size of rfline_post (in this case)?
>> whos -file rf_data/rf_post_ln1.mat
Name Size Bytes Class Attributes
rfline_post 18173x1 145384 double
tline_post 1x1 8 double
Walter Roberson
Walter Roberson el 23 de En. de 2012
http://www.mathworks.com/help/techdoc/ref/whos.html
s = whos('rfline_post', '-file', 'rf_data/rf_post_In1.mat');
s.size

Iniciar sesión para comentar.

Más respuestas (1)

Daniel
Daniel el 24 de En. de 2012
Hi,
Here is how i have done it. Thanks Walter! :)
lineLengths = [];
for i=1:no_lines
fileName = ['rf_data/rfline_pre_' num2str(i) '.mat'];
s_pre = whos('rfline_pre', '-file',fileName );
lineLengths_pre=[lineLengths s_pre.size];
fileName = ['rf_data/rfline_post_' num2str(i) '.mat'];
s_post = whos('rfline_post', '-file',fileName );
lineLengths_post=[lineLengths s_post.size];
end
maxLength_pre = max(lineLengths_pre);
maxLength_post = max(lineLengths_post);
rfAllLines_pre = zeros(maxLength_pre,no_lines);
rfAllLines_post = zeros(maxLength_post,no_lines);
tlineAll_pre = [];
tlineAll_post = [];
for i=1:no_lines
fileName = ['rf_data/rfline_pre_' num2str(i) '.mat'];
cmd = ['load ', fileName];
eval(cmd);
rfAllLines_pre(1:max(size(rfline_pre)),i)=rfline_pre;
tlineAll_pre = [tlineAll_pre tline_pre];
fileName = ['rf_data/rfline_post_' num2str(i) '.mat'];
cmd = ['load ', fileName];
eval(cmd);
rfAllLines_post(1:max(size(rfline_post)),i)=rfline_post;
tlineAll_post = [tlineAll_post tline_post];
end

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by