필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Judong Lee
Judong Lee 2016년 2월 24일
편집: Stephen23 2019년 6월 19일
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
Jos (10584)
Jos (10584) 2016년 2월 24일
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 2016년 2월 24일
편집: Stephen23 2019년 6월 19일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2016년 2월 24일
Please read http://www.mathworks.com/matlabcentral/answers/196952#answer_174587 . Stephen has discussed the topic exhaustively.

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by