I'm trying to make a for-end loop that outputs a complete table of the variables t and y.

조회 수: 1 (최근 30일)
for t=1:100
y=1-exp(-t/50);
table(t,y)
end
I'm trying to make a for-end loop that outputs a complete table of the variables t and y. However, when I do this the way I think it would work, it pumps out 100 different, individual tables.
These are my instructions. Using a for-end loop, create two vectors and display in a table: i. T contains all integers between 1 and 100 ii. Y contains 100 elements where each element is Yn=1-e-T/50
Is there a way to make a single table? I don't really care about labels. I'm struggling to figure out how to go about doing this.

채택된 답변

bio lim
bio lim 2016년 12월 3일
Try this:
for t=1:100
y(t)=1-exp(-t/50);
end
t = 1:100;
A = [t' y'];
T = array2table(A,...
'VariableNames',{'t','y'})
Output:
T =
t y
___ ________
1 0.019801
2 0.039211
3 0.058235
4 0.076884
5 0.095163
6 0.11308
7 0.13064
8 0.14786
9 0.16473
10 0.18127 ....

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by