Hi. I want to define repetitive vectors from notepad data using loop

1 vue (au cours des 30 derniers jours)
Judong Lee
Judong Lee le 24 Fév 2016
Modifié(e) : Stephen23 le 19 Juin 2019
I am using an analysis program and it gives me a data in form of steel#.out. I made a code to load this data like
steellayer=#;
for ii = 1:steellayer
load(['Steel' num2str(ii) '.out'])
end
and from this code I have Steel1, Stee2, Steel3, .... Steel#.
Each data is a 1000x3 matrix and I just need second and third column from each matrix.
Second column is 'stress' and third column is 'strain' I want to have 'strain1', 'strain2','strain3'.....,'strain#' and 'stress1','stress2','stress3'...,'stress#' for each matrix
I can define each vector but it is not efficient since # varies by chases and I need to change it all the time.
Therefore, I want to make those vectors automatically no matter what # is.
I tried to make it using 'eval' function like this
for n=1:steellayer
eval(['Strain', int2str(steellayer),' = Steel',int2str(steellayer)'])
end
but I cannot pick a certain column and it just makes same matrix as Steel1.... Steel#.
I would really appreciate for any help.
Thanks.
  2 commentaires
Jos (10584)
Jos (10584) le 24 Fév 2016
Don't! Instead of using variables A1, A2, ... Ax, use a single variable, like a cell array A{k}, an array of structs A(k).data, or perhaps a regular arrays A(k,:), to store and process your data. This avoids the evil eval construction.
To generate column headers in a text file simply use fprintf as in
fprintf(fid,'Steel%02d',k)
Stephen23
Stephen23 le 24 Fév 2016
Modifié(e) : Stephen23 le 19 Juin 2019
Don't!
Load your data into one variable:
for k = 1:numel(files)
S(k) = load(files{k});
end
Or put your data into one cell array or one numeric array... whatever suits your data best.

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 24 Fév 2016
Please read http://www.mathworks.com/matlabcentral/answers/196952#answer_174587 . Stephen has discussed the topic exhaustively.

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by