Printing table using fprintf

I have the following code; my problem is that in for loop i want to give different names Ti(for i=3 )to tables . For this i try to use fprintf but it doesn't work. Any ideas?
clc
clear
job={'J1';'J2';'J3';'J4'};
A=[4;10;7;9];
B=[8;13;6;11];
Sum=A+B;
u1=table(job,A,B,Sum)
u2=sortrows(u1,4,'descend');
t=removevars(u2,{'Sum'})
t1=t(1,:)
for i=1:3
Ti=[t(i+1,:);t1]
end
with this code, i got all 3 tables with name Ti.

 Accepted Answer

The best you can do is to assign them to a cell array:
for i=1:3
T{i}=[t(i+1,:);t1];
end
and then address them as ‘T{1}’ and similarly for the other two. (Numbered variables are poor programming practice.)

2 Comments

Thanks a lot .
As always, my pleasure!

Sign in to comment.

More Answers (1)

KSSV
KSSV on 21 Apr 2020
Why you want to use fprintf for table? Read about writetable.

1 Comment

bcoz with this after for loop , when i want to perform some operations on these tables (say on Ti for i= 2) ....operations are performed on last Ti for i=3 ..not on Ti for i=2

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!