필터 지우기
필터 지우기

Analyze a variable number of datas

조회 수: 3 (최근 30일)
Peter
Peter 2015년 11월 11일
댓글: Thorsten 2015년 11월 11일
Dear all, I have a changing number of data to be analyzed. How can I do it the smart way without an if condition (copy and paste with ascending numbers) and without the "eval" instruction which I used to far. Simple example plotting two waves (with one if condition). How should I write the code to be flexible to plot 1, 2 or three waves, depending on the result (size(a,1)) I get? Looking forward to your advice. Thanks a lot!
t = 0:0.1:2*pi;
a = [sin(t); cos(t)];
figure
if size(a,1)==2
subplot(2,1,1)
plot(a(1,:))
subplot(2,1,2)
plot(a(2,:))
end

답변 (1개)

Thorsten
Thorsten 2015년 11월 11일
편집: Thorsten 2015년 11월 11일
N = size(a,1)
for i=1:N
subplot(1,N,i), plot(a(i,:))
end
  댓글 수: 2
Peter
Peter 2015년 11월 11일
Yes, thanks - I see, my example was to simple. Indeed, this is the solution for the subplot, but I do have some uicontrol elements and variable names as well. This is what puzzles me, because I do not get along with the arrays in this case...
Thorsten
Thorsten 2015년 11월 11일
Please provide some example of your uicontrol elements and variable names and the code you have so far.

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

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by