How can i plot a structure array?
조회 수: 5 (최근 30일)
이전 댓글 표시
Hello all,
I have a structure array containing multiple trials. I would like to plot the singl trials, but change the trials with the arrows (so that I don't have to give the single command). I wrote this code:
for b= 1:length(fields_trials)
plot (Trials.(['a_' int2str(a)]));
end;
댓글 수: 3
Stephen23
2016년 4월 8일
편집: Stephen23
2016년 4월 8일
@Fabio Castro: rather than using dynamic fieldnames, you should consider using a non-scalar structure. Using a non-scalar structure will make your code much simpler:
S(1).trial = [1,2,3];
S(2).trial = [4,5,6];
S(3).trial = [7,8,9];
Then accessing the contents of the structure is really simple:
>> S(1).trial % one element
ans =
1 2 3
>> vertcat(S.trial)
ans =
1 2 3
4 5 6
7 8 9
And you can use indexing to access any elements of the array:
>> vertcat(S([false,true,true]).trial)
ans =
4 5 6
7 8 9
Using a non-scalar array would make your code simpler, faster, and less buggy. You shoudl try it.
답변 (1개)
Walter Roberson
2016년 4월 8일
편집: Walter Roberson
2016년 4월 8일
for b= 1:length(fields_trials)
plot (Trials.(['a_' int2str(a)]));
hold on
end
댓글 수: 6
Walter Roberson
2016년 4월 8일
Is there to be one subplot per field? Or do you want something like a waterfall plot?
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!