Get last row of many matrices (ASCII text files) and create a new matrix from these rows
Posted
by
nofunsally
on Stack Overflow
See other posts from Stack Overflow
or by nofunsally
Published on 2012-12-08T20:49:06Z
Indexed on
2012/12/09
5:05 UTC
Read the original article
Hit count: 96
I have over a thousand matrices (6 x 2000, ASCII files, comma delimited) that I generated from MATLAB. I want to get the last row of each matrix / text file and save them in a new matrix / text file. The text files have crazy names so when I load them I can name them whatever. Right now I would do this to achieve my goal:
% A = load('crazyname.txt');
% B = load('crazynameagain.txt');
% C = load('crazynameyetagain.txt');
A = [5 5 5; 5 5 5; 1 1 1];
B = [5 5 5; 5 5 5; 2 2 2];
C = [5 5 5; 5 5 5; 3 3 3];
D(1,:)=A(end,:);
D(2,:)=B(end,:);
D(3,:)=C(end,:);
I will create each command (e.g. load, building D step by step) in Excel by combining text cells to create a command. Is there a better way to do this? Could I load / assign the matrices with a name that would better suit them to be used in a for loop? Or is some other MATLAB command that would facilitate this?
Thanks.
© Stack Overflow or respective owner