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

1 view (last 30 days)
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.

Accepted Answer

bio lim
bio lim on 3 Dec 2016
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 ....

More Answers (0)

Categories

Find more on Loops and Conditional Statements 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!