Hi. I want to define repetitive vectors from notepad data using loop
조회 수: 1 (최근 30일)
이전 댓글 표시
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)
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)
답변 (1개)
Jan
2016년 2월 24일
Please read http://www.mathworks.com/matlabcentral/answers/196952#answer_174587 . Stephen has discussed the topic exhaustively.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!