# Creating a table of values from for loops

조회 수: 48(최근 30일)
Jen 2014년 11월 20일
댓글: emory gregory 2021년 4월 22일
Say x increases from 10 to 50 in increments of 5, and y increases in increments of 10 from 0 to 100. x and y are passed through a function 'func'.
for i = 10:5:50
for j = 0:10:100
func(i,j)
end
end
How do I print the output values in a table such that each value matches up to the 'x' and 'y' inputs. Like this:
xlabel
10 15 20 25 30 35 40 45 50
ylabel
0
10
20
30
40
50
60
70
80
90
100

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

### 답변(1개)

Andrew Reibold 2014년 11월 20일
I apologize for posting this as a comment.
This will make a table of your values, without the labels on the sides. I guess you could add them as an extra row and column if you wanted. Idk.
X = 10:5:50;
Y = 0:10:100;
for i = 1:length(X)
for j = 1:length(Y)
output = X(i)*2+Y(j); %Fake Function (2x+y)
combined_output(j,i) = output;
end
end
##### 댓글 수: 1표시숨기기 없음
emory gregory 2021년 4월 22일
You're a lifesaver 7 years later! Thank you!

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

### 범주

Find more on Labels and Annotations in Help Center and File Exchange

### 태그

아직 태그를 입력하지 않았습니다.

### Community Treasure Hunt

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

Start Hunting!

Translated by